我有以下标记:
<label class="radio">
<input class="radio" type="radio" name="month_type" value="0" checked="checked">
On day 5
</label>
我需要将文本从“第 5 天”更改为“第 6 天”。选择需要从输入向上到标签。
我已经尝试过:
$("input[name='month_type']").parent().text(''); // the result is an empty string
$("input[name='month_type']").parent().contents().filter(function(){
return this.nodeType === 3; // Uncaught SyntaxError: Unexpected token ILLEGAL
}).remove();
运气不好。
最佳答案
试试这个:- http://jsfiddle.net/adiioo7/4s2eV
JS:-
$("input[name='month_type']").parent().html(function(){
return $(this).html().replace("On day 5","On day 6");
});
关于javascript - 更改子节点的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20399596/