Php jQuery单击函数和回调数组
我是jQuery新手,在理解函数方面有问题 我有以下HTML代码结构:Php jQuery单击函数和回调数组,php,javascript,jquery,Php,Javascript,Jquery,我是jQuery新手,在理解函数方面有问题 我有以下HTML代码结构: <ul class="result"> <li id="a"></li> <li></li> //will be added through a loop depending on input </ul> //将根据输入通过循环添加 这个jQuery代码: $(document).ready(function() { //chang
<ul class="result">
<li id="a"></li>
<li></li> //will be added through a loop depending on input
</ul>
//将根据输入通过循环添加
这个jQuery代码:
$(document).ready(function() { //changes are possible when the page has fully loaded
$('.inp').keyup(function() { //executes keyup function to the field class "inp"
var inp = $(this).attr('value'); //sets a variable with the value of input from class="inp"
$.post('ajax/file.php', {inp:inp}, function(data) { //posts that value to file.php as variable inp and executes the function (data) to this
$('.result').html(data); //adds the returned result into HTML content as a first element in the set of class="result" => <li>
$('.result li').click(function() { //executes click function when clicking li element
var result_value = $(this).text(); //sets a variable and prepares something as text
$('.inp').attr('value', result_value); //fills value attribute of field class "inp" with the variable result_value
$('.result').html(''); //???
});
});
});
});
$(document).ready(function(){//当页面完全加载时,可以进行更改
$('.inp').keyup(function(){//对字段类“inp”执行keyup函数
var inp=$(this).attr('value');//使用class=“inp”中的输入值设置变量
$.post('ajax/file.php',{inp:inp},function(data){//将该值作为变量inp发布到file.php,并执行该函数(data)
$('.result').html(数据);//将返回的结果作为class=“result”=>
$('.result li')。单击(function(){//在单击li元素时执行单击函数
var result_value=$(this).text();//设置变量并准备文本形式的内容
$('.inp').attr('value',result_value);//用变量result_value填充字段类“inp”的value属性
$('.result').html('');/???
});
});
});
});
现在我的问题是什么$('.result').html('')代码>是否?$('.result').html('')
将.result
的html设置为空字符串。
因此,在您的场景中,$('.result').html('';将结果类元素的html设置为null
<ul class="result">
</ul>
其次,您在“file.php”中使用了错误的方法,而不是使用以下代码:
echo '<li>'.$row["name_1"].'</li>';
echo '<li>'.$row["name_2"].'</li>';
echo '<li>'.$row["name_3"].'</li>';
echo'。$row[“name_1”]。 ;
回显“”.$row[“name_2”]。 ”;
回显“”.$row[“name_3”]。 ”;
$('.result').html('')代码>清除
的内容
$('.result').html('')
,将.result
ul
的html设置为空,它删除ul
$('.result').html('')中的所有内容
将带有类结果的标记的内部html设置为空,我想它将使现有的
通过循环添加,具体取决于输入。参考