我定义了这个html div标记:
<div style="height:100px; width:100px" class="total-title">
first text
</div>
我有jquery代码来更改其值:
$('div.total-title').html('test');
But this does not change the content of the div.
我定义了这个html div标记:
<div style="height:100px; width:100px" class="total-title">
first text
</div>
我有jquery代码来更改其值:
$('div.total-title').html('test');
But this does not change the content of the div.
如果你的值是纯文本(比如"test"),你也可以使用text()方法.这样地:
$('div.total-title').text('test');
无论如何,关于您正在分享的问题,我认为您可能会在将DIV的HTML代码发送到浏览器之前调用JavaScript代码.请确保在<;脚本>;标记中的<;div>;之后调用jQuery行,或者在如下所示的语句中调用jQuery行:
$(document).ready(
function() {
$('div.total-title').text('test');
}
);
this way the script executes after the HTML of the div is parsed by the browser.