jQuery .wrap(),锚点和IE [英] jQuery .wrap(), anchors and IE

查看:76
本文介绍了jQuery .wrap(),锚点和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <$ c我试图用jQuery(v1.2.6)在一段代码中包装一个锚标签$ c> var link = $('< a>).attr('href','http://www.foo.bar'); 
$('#block')。wrap(link);

这在所有浏览器中都很好,但是(你猜对了)Internet Explorer(我可以使用的所有版本用来测试它)。我从其他案例知道,当你通过JavaScript插入代码时,IE是hella挑剔的,但在这种情况下,我只是不知道这个简单的锚元素会出现什么问题?任何人有想法?顺便说一句:我已经尝试通过 $('< a>< / a>)不幸的生成锚点,这对我来说没有什么不同。



非常感谢!

解决方案

更新我的jQuery到1.3 +做了这个诀窍。

显然在jQuery 1.2中 var a = $('< a>'); .6和更早版本将创建一个IE认为无效的代码块,因此会拒绝将其插入到DOM树中。


I am trying to wrap an anchor-tag around a block of code using jQuery (v1.2.6) by doing the follwing:

var link = $('<a>').attr('href','http://www.foo.bar');
$('#block').wrap(link);

This works perfectly fine in all browsers but (you guessed it) the Internet Explorer (all versions I can use to test it). I do know from other cases that the IE is hella picky when you insert code via JavaScript, but in this case I just don't know what could be wrong with this simple anchor element? Anyone got an idea? Btw: I already tried generating the anchor via $('<a></a>') as suggested on several other posts unfortunately, makes no difference for me.

Thanks a whole lot!

解决方案

Updating my jQuery to 1.3+ did the trick.

Apparently var a = $('<a>'); in jQuery 1.2.6 and earlier will create a chunk of code that IE considers invalid and therefore will refuse to insert it into the DOM tree.

这篇关于jQuery .wrap(),锚点和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆