jQuery text() Method
jQuery text() Method
我有这个代码:
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()
您不能返回红色文本,而是将其包装在html
中并返回它;这样的事情应该适合您:
$('#eform input').each(function() {
if (this.className.indexOf('required') !== -1) {
$(this).closest('.rowElem').find('label').html(function(_, txt) {
return '<span style="color:red">*</span>' + txt;
});
}
});
我在这里使用了 .html()
方法而不是 .text()
方法。
相关文章:
- 如何将输入(type=text)从html表单传递到javascript函数
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- 在文本区域中使用jQuery.text()保持换行符
- 用Javascript添加带有#text的tr元素
- 当用户按下回车键时,自动在text区域/text中插入消息
- 修正案'text'的元素
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部
- W3验证器->使用<脚本类型=“;text/javascript”>在html的正文中
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- 当method=post时,jQueryAjax返回404
- 我如何在INPUT TEXT中使用这个Javascript和jQuery
- <text区域>在我的html中包含event.keycode==13之后,wrap就不起作用了
- 从所有下拉菜单中选择val和text
- 调用laravel{{action(Controller@method}}通过传递vue.js数组中的变量
- 节点,express应用程序返回text/javascript响应头(Content-Type),尽管设置了applic
- .val()返回未定义的.text返回随机代码
- JSTree's data.rslt.obj.text()返回一个文本数组,而不是所需节点的文本
- jQuery - text() method?
- jQuery text() Method
- Object #<Text> has no method 'getBoundingClientRec