Javascript 如何用ascii字符更新html元素?

Javascript 如何用ascii字符更新html元素?,javascript,jquery,html,Javascript,Jquery,Html,我试图添加ascii字符⚠到某个元素的标题属性 当我使用jQuery(this)[0].title=title;“时,我得到了原始值。我还尝试了.attr('title',value)知道如何用ascii更新title属性吗 范例 编辑:查看您的JSFIDLE后,我意识到您遇到了什么问题以及如何修复它。您的选择器不正确,需要html() $(document).ready(function() { $("label").each(function(index){ var

我试图添加ascii字符
到某个元素的标题属性

当我使用jQuery(this)[0].title=title;“
时,我得到了原始值。我还尝试了
.attr('title',value)
知道如何用ascii更新title属性吗

范例

编辑:查看您的JSFIDLE后,我意识到您遇到了什么问题以及如何修复它。您的选择器不正确,需要html()

$(document).ready(function() {
  $("label").each(function(index){  
   var title = jQuery(this).attr('title');
                    title += '
 ⚠ Stats are incomplete due to the video being recently published'
                    jQuery(this).html(title);
  });
});
更新的JSFIDLE:

这个问题在这里得到了回答:

.text()添加到变量中。像这样:


jQuery(this)[0]。title=title.text()

编辑:查看您的JSFIDLE后,我意识到您遇到了什么问题以及如何修复它。您的选择器不正确,需要html()

$(document).ready(function() {
  $("label").each(function(index){  
   var title = jQuery(this).attr('title');
                    title += '
 ⚠ Stats are incomplete due to the video being recently published'
                    jQuery(this).html(title);
  });
});
更新的JSFIDLE:

这个问题在这里得到了回答:

.text()添加到变量中。像这样:


jQuery(this)[0]。title=title.text()

我提供的.text()解决方案是否可行?如果是这样的话,你能选择我的答案作为正确的答案吗?Thanks@SterlingBeason不,将.text()添加到字符串不起作用。@NullReference我用一个有效的JSFIDLE更新了我的答案。ascii字符不是问题所在。请查看我的更新答案。我提供的.text()解决方案是否可行?如果是这样的话,你能选择我的答案作为正确的答案吗?Thanks@SterlingBeason不,将.text()添加到字符串不起作用。@NullReference我用一个有效的JSFIDLE更新了我的答案。ascii字符不是问题所在。请看我的最新答案。