IE8:“;ln.innerHTML要么为null要么不是对象”;
IE8: "ln.innerHTML is either null or not an object"
我正在使用nicedit.js wysiwyg库,但插入链接的按钮出现问题。
单击按钮会弹出一个面板,您可以在其中输入url和标题,然后单击提交:链接应该插入到您的光标位置。但我在IE8中得到了以下错误:
ln.innerHTML为null或不是对象
错误行为:
if (this.ln.innerHTML == tmp) {
全代码
var nicLinkButton = nicEditorAdvancedButton.extend({
addPane : function() {
this.ln = this.ne.selectedInstance.selElm().parentTag('A');
this.addForm({
'' : {type : 'title', txt : 'Add/Edit Link'},
'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}},
'title' : {type : 'text', txt : 'Title'},
'target' : {type : 'select', txt : 'Open In', options : {'' : 'Current Window', '_blank' : 'New Window'},style : {width : '100px'}}
},this.ln);
},
submit : function(e) {
var url = this.inputs['href'].value;
if(url == "http://" || url == "") {
alert("You must enter a URL to Create a Link");
return false;
}
this.removePane();
if(!this.ln) {
var tmp = 'javascript:nicTemp();';
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
if (this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
if(this.ln) {
var oldTitle = this.ln.title;
this.ln.setAttributes({
href : this.inputs['href'].value,
title : this.inputs['title'].value,
target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value
});
// set the link text to the title or the url if the old text was the old title
if (this.ln.innerHTML == oldTitle) {
this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value;
};
}
}
});
即使是nicedit.com主页上的例子也没有插入链接,尽管它也没有显示这个错误。
InternetExplorer不像其他浏览器那样处理innerHTML,尤其是当您谈论的是表元素时。请参阅此处进行讨论。
根据你的具体情况,有各种各样的修复方法——这个建议涵盖了大多数情况。或者,如果您想兼容IE,您可能需要删除并重新创建表元素,而不是更新它们的innerHTML。
一些简单的防御逻辑应该有效:
if (!this.ln.innerHTML || this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
当没有选择文本时会出现此问题
我对nicEdit的诀窍是,在没有选择文本的情况下,将通过"添加链接"表单提供的标题粘贴到文档中并选择它,然后其余代码的工作原理与选择文本时的工作原理相同。
我使用了下面链接中描述的函数pasteHtmlAtCaret来粘贴标题
在可编辑内容的div 中的插入符号处插入html
var selected = getSelected();
if (selected == '')
pasteHtmlAtCaret(this.inputs['title'].value,true);
if(!this.ln) {
var tmp = 'javascript:nicTemp();';
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
if (!this.ln.innerHTML || this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
getSelected也是一个简单的函数,如下所示
function getSelected()
{
if (document.selection)
return document.selection.createRange().text;
else
return window.getSelection();
}
相关文章:
- 谷歌地图API-“;toGeoJson”;返回几何体为null的对象
- 验证对象是否为null Javascript/Angularjs
- 对象为null或IE9中存在未定义错误
- 如何计算一个对象中五个属性中有多少是非null的
- Microsoft JScript运行时错误:无法获取属性'的值;样式':对象为null或未定义
- javascript对象显示为null,但object.properties返回数据
- global.getElementById('..')为null或不是对象
- IE8错误:为null或不是对象,但仍然可以跟踪/控制台注销
- AJAX请求中的JSON对象为Null或空
- Highcharts无法设置属性'的值;要点':对象为null或未定义
- ui.selectmenu投掷'this.newelement.0'为null或不是对象
- 添加到序列化数组中的复杂对象在服务器端始终为 null
- 什么是 ClojureScript 类似地将不存在的对象值设置为 JavaScript 中的 null
- Javascript:将类/对象引用设置为 NULL,内存中的子对象/类会发生什么
- 为什么引用 = null 不会影响引用的对象
- 类型错误:'null'不是对象(正在评估'响应.productType')
- IE错误:无法设置属性'的值;样式':对象为null或未定义
- 我的代码给了我一条错误消息:GetElementById()为null或不是对象
- IE8对象当对象包含null值时应出现错误
- 为iframe获取对象null.使用jsdom和所需选项创建iframe