我是一個jQuery的開始,所以如果它質量不好,請原諒我。jquery函數中的索引是什麼意思
我想知道index
在函數中意味着什麼,以及它究竟指的是什麼。以前我認爲它是指像索引號碼0,1,2,3等,但當我通過1,2,3代替索引我的代碼停止工作。我檢查了這種類型,它顯示我number
數據類型。 現在讓我究竟是什麼即時通訊做錯了,指數和元素在jQuery中的大多數地方,我發現像這樣的概念 -
function(e){
}
我的工作代碼 -
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('li').html(function(index, oldHtml) {
//alert(typeof($(this).index()));
return oldHtml + '!!!'
});
});
</script>
</head>
<body>
<ul>
<li>This is List item 1</li>
<li>This is List item 2</li>
<li>This is List item 3</li>
<li>This is List item 4</li>
<li>This is List item 5</li>
</ul>
</body>
</html>
我嘗試 - -
$('li').html(function(3, oldHtml) {....
$('li').html(function("3", oldHtml) {....
$('li').eq(3).html(function("3", oldHtml) {......
Thx對於一個非常簡單和簡明的解釋。我喜歡這個地方..真的是一個程序員的天堂...只是一點幫助..可以提供一個初學者的參考,因爲jQuery文檔似乎不大開始:) – Trialcoder
我會建議你通過入門教程jQuery網站本身。一旦你習慣了基本的概念,就可以使用API參考。 –