我有一个id为toptitle
的h1
,它是动态创建的,我无法更改HTML.
<h1 id="toptitle">Profile</h1> // Changing only when it is Profile
// to
<h1 id="toptitle">New word</h1>
Note: If the text is Profile
, then change it to New word
.
我有一个id为toptitle
的h1
,它是动态创建的,我无法更改HTML.
<h1 id="toptitle">Profile</h1> // Changing only when it is Profile
// to
<h1 id="toptitle">New word</h1>
Note: If the text is Profile
, then change it to New word
.
像这样的事情应该会奏效:
$(document).ready(function() {
$('#toptitle').text(function(i, oldText) {
return oldText === 'Profil' ? 'New word' : oldText;
});
});
这仅在内容为Profil
时替换内容.参见jQuery API中的text
.