我是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() { //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(''); //???
});
});
});
});
現在我的問題是什麼$('.result').html('');
呢?
'$( '的結果。 ')HTML('');',設定的的''.result'到ul'空白的HTML,它刪除的一切,就是'ul'內 –
'$('。result')。html(''); '設置與類結果以空白標籤的內部HTML,我想是將使'
'從現有'
//將通過一個循環中加入根據輸入
'。請參閱http://api.jquery.com/html/#html2 – dreamweiver