在IE7中,字符串的第一个大写字母发生了断裂
Uppercase first letter of a string chrashes in IE7
actualizarTituloWeb('brand name - '+seccion.toLowerCase().replace(/(?:_| |'b)('w)/g, function(str, p1) { return p1.toUpperCase()}));
,
function actualizarTituloWeb(titulo){
$( 'title' ).html ( titulo );
}
也试过:
function actualizarTituloWeb(titulo){
titulo = titulo[0].toUpperCase() + titulo.substring(1);
titulo = titulo.toLowerCase();
$( 'title' ).text ( titulo );
return false;
}
和section的值如'reserva', 'ofertas',…
我真的不知道为什么不工作,但这实际上使整个脚本崩溃(可以在这里进行现场测试:http://toniweb.us/gm2)在IE7和当前文档的标题都没有更新,
你知道我错过了什么吗?
编辑——
刚刚意识到问题在这一行!为什么?
titulo = titulo[0].toUpperCase() + titulo.substring(1);
请注意:我们不能在这里使用CSS来实现这一点,因为它将用于document.title
在JScript <= 5.7 (IE 7)中,您不能像访问数组一样访问字符串。你必须用String.charAt()
代替。类数组访问在ES 5中是标准化的。
titulo = titulo.charAt(0).toUpperCase() + titulo.substring(1);
另外$('title').text(titulo);
不工作。在版本8之前的ie中,您不能通过title-元素的textContent来设置(或获取)标题。
<html>
<head>
<title>test</title>
</head>
<body>
<script type='text/javascript'>
document.getElementsByTagName('title')[ 0 ].firstChild // null in IE <= 8
// IE 9 (and other browser): text node with nodeValue 'test'
</script>
</body>
</html>
使用document.title document.title = titulo;
只要稍微修改一下正则表达式模式,就可以实现预期的行为
actualizarTituloWeb('brand name - ' + seccion.toLowerCase().replace(/(^|'s|'-)(.)/gi, function(c) { return c.toUpperCase()}));
你为什么不这样做呢:
var str = "blah blah";
str = str.toLowerCase();
str = str[0].toUpperCase() + str.substring(1);
document.title = str;
相关文章:
- 正好包含2个大写字母和3个数字的正则表达式
- 创建时选择Nav大写字母
- 带有大写字母的棱角分明的光滑属性
- Regex模式,用于检查字符串中每个单词的第一个字母(如果是Javascript中的大写字母)
- 有没有一个函数会忽略javascript中的大写字母
- 如何使用至少一个数字、一个大写字母和6-20个字符验证密码
- 查找大写字母的简单正则表达式是返回小写字母
- 忽略任何非小写字符(如数字、大写字母和符号)并获取k的值
- 为什么属性存在于对象实例上,即使其原型发生了更改
- 带撇号的字母消失了
- 正则表达式和 javascript:匹配数字后跟空格和大写字母之间的所有内容
- Javascript函数 - 通过引用复制,但这里发生了什么
- 将 CSS 类添加到以大写字母开头的行
- 提取大写字母 ( 英语 ) |首选方法
- 如何在提示中接受大写字母?JS
- 套接字发生了什么's在'断开连接'事件(服务器端)
- 这段代码中发生了什么
- Wamp没有识别出我的代码发生了更改
- 如何检查输入框值在使用淘汰之前是否发生了更改
- 在IE7中,字符串的第一个大写字母发生了断裂