私はあなたが検索ボックスの値をユーザーが結果をクリックするたびに更新するように求めているものを理解してから。
ので、ここであなたはそれを成し遂げることができる方法の簡単なデモである場合:場合
// wait until we can safely manipulate the page.
$(document).ready(function() {
// listen for click events on the results
$(".results-container > .result").on("click", function(event) {
// update the search box value
$(".search-panel > .search-box").val($(this).text());
});
});
:ここ
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Selecting Search Results</title>
<!-- NOTE: we need jQuery so lets include it -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>
<!-- NOTE: this is your search panel -->
<div class="search-panel">
<input type="text" class="search-box"/>
</div>
<!-- NOTE: this is your results container -->
<div class="results-container">
<div class="result">Lorem Ipsum 1</div>
<div class="result">Lorem Ipsum 2</div>
<div class="result">Lorem Ipsum 3</div>
<div class="result">Lorem Ipsum 4</div>
<div class="result">Lorem Ipsum 5</div>
<div class="result">Lorem Ipsum 6</div>
<div class="result">Lorem Ipsum 7</div>
<div class="result">Lorem Ipsum 8</div>
</div>
<!-- NOTE: this simple script updates the search box value -->
<script type="text/javascript">
$(document).ready(function() {
$(".results-container > .result").on("click", function(event) {
$(".search-panel > .search-box").val($(this).text());
});
});
</script>
</body>
</html>
は、検索ボックスの値を更新のjQueryのブレークダウンですバニラJavaScriptを使用して、代わりにこれを使用したいと考えています。
// wait until we can safely manipulate the page.
document.addEventListener("DOMContentLoaded", function() {
// get the results
var results = document.querySelectorAll(".results-container > .result");
for(var i = 0; i < results.length; i++) {
// listen for click events on the results
results[i].addEventListener("click", updateValue);
}
// this function handles the "click" event
function updateValue() {
// update the search box value
document.querySelector(".search-panel > .search-box").value = (this.textContent || this.innerText);
}
}, false);
また、この機能を実装していませんforループでは、関数をループに入れるのは悪い習慣なので、詳細はthisページを参照してください。
幸運とすべてのベスト。
'$ .post'でどんな種類の' output'を得ていますか? –
こんにちはグルプラサード、 私は取得していますが、出力でのフォーマットを下回っている: