【发布时间】:2010-12-13 16:01:11
【问题描述】:
我正在实现一个解析器,它在 contenteditable div 的顶层查找匹配模式的文本节点。我当前的代码:
//$this is the jQuery object of the contenteditable div
$this.keydown(function(event){
//space bar or enter key
if(event.keyCode == 32 || event.keyCode == 13){
// see how many nodes there are in the div
alert($this.contents().length);
$this.contents().each(function(){
//check if it is a text node
if(this.nodeType == 3){
//echo if it is a text node
alert(this.data);
}
});
});
使用“Check it out”内容,firefox 和 chrome 会输出如下内容:
“1”(第一个警报)
“检查一下”(第二个警报)
而 IE8 将输出以下内容:
12(第一次警报)
接下来是 12 个警报,每个字符一个。
Anyhoo,我想做的是将所有字符放入 IE 中的单个文本节点中。有什么想法吗?
【问题讨论】:
标签: javascript jquery internet-explorer contenteditable