IE7不完全支持javascript的insertBefore方法吗?
我有以下代码,可以在 Chrome、IE8 和 FF 中完美运行。但是,当我使用 IE7 进行测试时,出现错误。有人知道这里发生了什么事吗?
function do_replace(s, p1,p2,p3,child_node,syn_text) {
reg = new RegExp('[h\|H][1-7]');
if(p1.length>0){ //this might not be necessary
//create textnode
var text_node = document.createTextNode(p1);
child_node.parentNode.insertBefore(text_node,child_node); //errors out here in IE7
}
代码在最后一行出错 - IE7 给出“htmlfile:无效参数”。当我通过调试器查看代码时出错。运行此脚本时,child_node、parentNode 和 text_node 的构成似乎与 Firefox 和 Chrome 相同。
有什么想法吗?还是IE7和其他浏览器一样不支持这种方法?
谢谢
I have the following code which works perfect in Chrome, IE8, and FF. However, I get an error when I'm testing it with IE7. Does anyone have a clue what's happening here?
function do_replace(s, p1,p2,p3,child_node,syn_text) {
reg = new RegExp('[h\|H][1-7]');
if(p1.length>0){ //this might not be necessary
//create textnode
var text_node = document.createTextNode(p1);
child_node.parentNode.insertBefore(text_node,child_node); //errors out here in IE7
}
The code errors out at the last line- IE7 give an "htmlfile: Invalid argument." error when I look at the code through a debugger. child_node, parentNode, and text_node appear to be formed identical to Firefox and Chrome when running this script.
Any ideas? Or does IE7 just not support this method as well as other browsers?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有让这个问题悬而未决,而是找出了我的代码出了什么问题:
我使用了一个广泛的框架集(哎呀!!),当我进行
text_node = document.createTextNode()
调用时,我 我没有在我的应用程序所在的框架中执行此操作。我通过显式调用框架来在其中创建对象来修复此问题:
执行此操作后,
insertBefore
方法完美运行!希望这对任何看这个问题的人都有帮助——我知道这花了我很长时间和很多挫败感才弄清楚!
Rather than leave this problem unsolved, I figured out what was wrong with my code:
I was using an extensive frameset(yuck!!) and when I made the
text_node = document.createTextNode()
call, I was not doing this in the frame that my application was in.I fixed this by explicitly calling out the frame to create the object in:
After doing this, the
insertBefore
method works perfect!Hopefully this helps anyone looking at this question- I know this took me a long time and lots of frustration to figure out!
IE7 支持 JavaScript 'InsertBefore' 函数。请记住,您必须仅在页面完全加载时使用此功能!
详细信息
JavaScript 'InsertBefore' function is supported by IE7. Remember that you have to use this function only when page is fully loaded!
Details