http://jsbin.com/ezecun/edit#javascript,htmlonkeyup方式太慢
我必須這樣寫,因爲它是動態製作的,下面列出的實際代碼。我在jsbin中簡化了一下。基本上它需要很長的時間來更新數組,使其不可用。
感謝您的關注。
CODE: PHP
echo "<label style='float:left'>Comments: </label> <textarea onKeyUp=\"editItemInCart(this.value,'comments',".$itemNum.")\" onChange=\"editItemInCart(this.value,'comments',".$itemNum.")\" >".$cart['comments']."</textarea><br />";
的JavaScript
function editItemInCart(newValue,fieldName,itemNum) {
jQuery.ajax({
type:"POST",
url: "editItem.html",
data: "newvalue=" + newValue + "&fieldname=" + fieldName + "&itemNum=" + itemNum,
})
//alert(newValue + fieldName + itemNum);
}
你對此有何看法? –
這不是關鍵事件,但腳本必須等待服務器響應AJAX查詢。您是否測量了editItem.html處理查詢需要多長時間? – JJJ
我希望它使用基於這兩個事件的新值更新數組。 頁面不到一秒鐘,沒問題。我認爲在等待不活動的時候增加一個延遲,然後更新會更好,所以它不會一直髮射。 – oneadvent