可以将所有需要更新的 HTML 内容合并到一个字符串中,最后再使用一次 doc.html() 方法进行更新。
示例代码:
// 不推荐的做法
$(document).ready(function(){
$('#div1').html('Hello');
$('#div1').html('World'); // 该操作会覆盖上一次的更新结果
});
// 推荐的做法
$(document).ready(function(){
var htmlContent = 'Hello';
htmlContent += 'World';
$('#div1').html(htmlContent); // 只用一次 html() 方法更新内容
});
上一篇:不能对数据框进行xtfrm操作。
下一篇:不能多次引用变量名“id”。