【发布时间】:2009-08-19 05:04:21
【问题描述】:
我正在尝试替换 Javascript 中的多行内容,IE 给我带来了麻烦。
在这里粘贴:http://jsbin.com/olahi/edit
解释我想要做什么: 这是我的 HTML:
<textarea id="editthis">
Hello from JS Bin
Whats up from JS Bin
Whats
up from JS Bin
</textarea >
还有我的 JS:
jQuery.fn.runReplacement= function(expr) {
return this.each(function() {
this.innerHTML = this.innerHTML
.replace(/Hello/ig, "Hey")
.replace(/Whats ?\n? ?up/ig, "Hey")
;
});
};
$(function() {
$("textarea").runReplacement();
});
在我的 JS(jQuery) 示例中,我只是想将 Hello 和 'Whats up' 替换为 'Hey'。
在 IE 中,前两行有效,但第三(和第四)行无效。在 Chrome 和 FF 中,所有 4 行都有效。
我看不出 IE 不支持 \n 的任何原因。我是不是做错了什么?
提前致谢。
谢谢大家,很高兴知道 IE 需要 /r/n 而不仅仅是 /n。
关于使我的代码跨浏览器的任何建议,而不仅仅是 IE 或其他任何东西。
谢谢!
【问题讨论】:
标签: javascript jquery regex internet-explorer