这是用于显示输出的 jquery 代码。但我在输入文本中使用现有值。 因此,数据可以显示,但我需要单击文本框并在文本框内更改以显示数据库中的项目。
我不想更改文本框的值。
$(document).ready(function(){
$('.search-box2 input[type="text"]').on("keyup input", function(){
/* Get input value on change */
var inputVal2 = $(this).val();
var resultDropdown2 = $(this).siblings(".result2");
if(inputVal2.length){
$.get("ajax2.php", {term: inputVal2}).done(function(data){
// Display the returned data in browser
resultDropdown2.html(data);
});
} else{
resultDropdown2.empty();
}
});
最佳答案
$(document).ready(function(){
const val = $('.search-box2 input[type="text"]').val();
$.get("ajax2.php", {term: val}).done(function(data){
// Display the returned data in browser
resultDropdown2.html(data);
});
});
关于javascript - Jquery:如何使用现有的输入文本值而不使用像 "change", "keyup"这样的交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59014239/