1
我们有一个标题删除符号代码
<title>Text – text</title>
我想用jQuery改变它
$('title').html($('title').html().replace('Text-text', ''));
但它不工作...
我们有一个标题删除符号代码
<title>Text – text</title>
我想用jQuery改变它
$('title').html($('title').html().replace('Text-text', ''));
但它不工作...
使用.text()
更换内容:
$('title').text('Text-text');
0如果在那里没有真正的HTML,是过度杀毒。
要只替换某些字符为题,用一个回调函数:
$('title').text(function(i,str) {
return str.replace('replace this','with this');
});
要替换的特殊字符,你需要用自己的Unicode编码,这是我用谷歌搜索“的unicode 8211”发现here :
$('title').text(function(i,str) {
return str.replace('\u2013','-');
});
我觉得有点难读。在任何情况下,“它不起作用”应该可能跟随实际发生的事情,事情失败等等。 –
它不会被任何东西取代 – Arti
看看[这个w3c学校](http://www.w3schools .com/jquery/tryit.asp?filename = tryjquery_dom_attr_set2)的例子。 – BrOSs