无法获取属性值'appendChild':对象为空或未定义"同时追加脚本到IE
"Unable to get value of the property 'appendChild': object is null or undefined" while appending script to IE
当我尝试将以下脚本附加到IE时,我得到这个错误:
"错误:无法获取属性'appendChild'的值:对象为空或未定义"
它在Chrome中工作良好,但在IE9上测试时发生了这种情况。有人能告诉我错误是什么吗?
// create script in document
var fbScript = document.createElement("script");
fbScript.type = "text/javascript";
// make script source the facebook plugin
fbScript.src = "http://connect.facebook.net/en_US/all.js#xfbml=1";
// append script to appropriate tab
document.getElementById('Tab' + tab_counter).appendChild(fbScript);
如果您的javascript代码在加载HTML的所有部分之前运行,则可能发生这种情况。尝试将此代码放入函数中,并在onload事件时触发它。或者使用更优雅的jQuery onload事件。大概是这样的
$().ready(function () {
var fbScript = document.createElement("script");
fbScript.type = "text/javascript";
// Make script source the facebook plugin
fbScript.src = "http://connect.facebook.net/en_US/all.js#xfbml=1";
// Append script to appropriate tab
document.getElementById("Tab" + tab_counter).appendChild(fbScript);
});
相关文章:
- "日期“;AJAX请求返回的类型值未定义
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- Angular promise return"未定义的“;值.NET MVC
- 得到"未定义不是函数“;使用显示原型图案时出错
- 为什么我会出现此错误"未捕获引用错误:未定义标题;
- jquery validate 1.8.1”;jQuery"是未定义的错误IE8
- "这个“;正在返回未定义的
- 得到"全局未定义“;全局变量定义清楚时出错
- "TypeError:t.start未定义”;,在fullcalendar.min.js中,同时在我的网站上使
- "未定义不是函数“;错误jQuery,.replaces,scrollTop
- "ctrl”;在指令中的LINK中未定义
- "未定义的“;当从Android向JavaScript传递数据时
- "无法读取属性'id'未定义的“;解析工厂中声明的数组时
- "未捕获的类型错误:未定义的不是函数“;当向输入字段添加值时
- jqueryui:"类型错误:this.menu.element未定义"
- 我可以't克服这个错误“;未定义的局部变量或方法`f'"任何原因
- "$"在Visual Studio中使用jQuery时未定义
- "$"未定义;jquery在<头部>;没有冲突的脚本或库
- 为什么"~未定义的“;在JavaScript中为-1