[英]Change a html5 Data-Attribute
嗨,我有一些與此代碼的問題。
我用它來存儲數據庫偏移量的偏移量值
button.remove('data-offset');
button.attr('data-offset', comoffset);
第一次觸發腳本時,按鈕會獲取新數據,一切正常。 但是在第二或第三次,數據偏移量將永遠不會再次被替換...
我使用以下代碼: 使用jquery更改data-attribute
Edit1:完整代碼
if (busy == false) {
busy = true;
comoffset = button.data('offset');
comoffset = comoffset + comlimit;
button.removeAttr('data-offset');
button.attr('data-offset', comoffset);
// start to load the next set of data
setTimeout(function() { displayComments(comlimit, comoffset,chat); }, 1000);
}
請使用removeAttr函數從標簽內部刪除所有arrtibute
button.removeAttr('data-offset');
首先,刪除屬性
button.removeAttr('data-offset');
然后使用:
button.attr('data-offset', comoffset);
您可以使用removeAttr()
刪除屬性
button.removeAttr('data-offset');
您可以使用attr()
設置屬性
button.attr('data-offset', comoffset);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.