嗨, 我的數組打印出來的頁面上的值時:爲什麼javascript「write()函數」在jQuery中引用元素時不起作用?
document.write(unsorted[i]+"<br/>");
,但不是在試圖把它放在一個div的jQuery
$("#no1").write(unsorted[i]+"<br/>");
這裏所指的元素是我的代碼:
$(function(){
var unsorted = new Array();
function randomNumber(x,y) { //gives a random number
return Math.floor((Math.abs(y - x) + 1) * Math.random()) + Math.min(x, y);
}
for(i=0; i<=33; i++){
unsorted[i]=randomNumber(0,33); //populates the array with random numbers
$("#no1").write(unsorted[i]+"<br/>"); //#no1 is a div
}
});
無論是我的代碼,jquery庫都經過測試,工作正常! 任何建議爲什麼我的做法是錯誤的感謝所有幫助 10X
不要通過讀寫'html()'來追加。這迫使瀏覽器序列化,銷燬並重新解析DOM內容,這很慢並且丟失了不可序列化的內容,如事件處理程序。改用'append()'。 – bobince 2010-11-10 13:28:37