下一行中的一行更改文本..在我更改它之前,我想检查文本是否不等于“活动”。我怎样才能做到这一点?:`.html('usa')`打印它
if ($(".myimg").parent('p').find(".status").html != 'Active') {
// change the text
$(".myimg").parent('p').find(".status").html('Paused');
}
任何帮助赞赏!
下一行中的一行更改文本..在我更改它之前,我想检查文本是否不等于“活动”。我怎样才能做到这一点?:`.html('usa')`打印它
if ($(".myimg").parent('p').find(".status").html != 'Active') {
// change the text
$(".myimg").parent('p').find(".status").html('Paused');
}
任何帮助赞赏!
使用.html()
来获得当前的HTML
var status = $(".myimg").parent('p').find(".status");
if (status.html() != 'Active') {
// change the text
status.html('Paused');
}
只需使用这样的:如果你想要得到的,或设定
var status = $(".myimg").parent('p').find(".status");
if (status.html() != 'Active') {
status.html('Paused');
}
$(".myimg").parent('p').find(".status").html(function(_,txt) {
return txt == 'Active' ? 'Paused' : txt;
});
,文字使用text()
:
var status = $(".myimg").parent('p').find(".status");
status.text(function(i, t) {
return t == 'Active' ? 'Paused' : 'Active';
});
个
参考文献: