javascript - 更改子节点的文本

标签 javascript jquery html

我有以下标记:

<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/

相关文章:

jquery - MVC 文本框的 @placeholder 或 placeholder 属性未被 jquery 更改

javascript - Backbone 集合 get(id) 方法

javascript - 如何在 HTML 页面中使用 jquery 或 javascript 发送邮件

javascript - 如何阻止页面滚动移动网站?

javascript - 如何转义ajax数据中的特殊字符?

html - CSS 按钮、默认颜色、悬停颜色和 :active color change

javascript replaceChild 不起作用

javascript - 我需要在网页中单击 <a> 标记时调用 Javascript 函数来显示和隐藏 <div> 内容

javascript - 警报随着 keyup 事件消失

html - 重复图像以将标题扩展到整个屏幕