javascript - jQuery text() 方法

标签 javascript jquery

我有这个代码:

JavaScript/jQuery:

$('#eform input').each(function() {
    if (this.className.indexOf('required') != -1) {
        $(this).closest('.rowElem').find('label').text(function(_, txt) {
            return '*' + txt
        });
    }
});

我怎样才能返回红色的星号??

最佳答案

return '<span style="color:red">*</span>' + txt

并使用.html()代替.text()

关于javascript - jQuery text() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18920578/

相关文章:

javascript - 单选按钮(如果单击)

jquery - 为什么连续显示和隐藏在此代码中出现错误?

ajax - 在动态创建的元素上使用 jQuery 时查找 $(this)

javascript - 如何使用 nvd3 工具提示将 'arrow' 添加到工具提示

javascript - jquery在asp.net中选择下拉列表控件

javascript - LocalStorage 选项卡中的更改日期

javascript - 如果 id 中的最后一个数字小于 i,则显示元素

jquery - 在 jQuery 中获取祖父

javascript - 检测外部损坏的链接

javascript - jQuery .load() 不会将数据加载到 <form></form> 中