将jQuery Library与document.write:IE冻结



可能重复:
为什么要拆分<脚本>标记。write((?

我的页面上有这个代码:

var print_popup = window.open("", "Booking", "width=950,height=680, scrollbars=1");
print_popup.document.write("<html xmlns='http://www.w3.org/1999/xhtml'>");
print_popup.document.write("<head>");
print_popup.document.write("<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>");
print_popup.document.write("</head>");
print_popup.document.write("<body>");
print_popup.document.write("<div class='element'>Hello</div>");
print_popup.document.write("<div class='element2'>Marco</div>");
print_popup.document.write("<script type='text/javascript'>$('.element').hide();</script>");
print_popup.document.write("</body>");
print_popup.document.write("</html>");
print_popup.document.close();

因此,当我打开弹出窗口时,我插入jquery库。然后,我想隐藏element。在Firefox/Chrome上没有问题;在IE(8(上,浏览器打开一个大约空白的弹出窗口,窗口被冻结(我需要强制关闭浏览器(。

我知道我应该用CSS隐藏元素,但对于其他操作,我需要jQuery。

为什么这样?我该怎么修?

编辑

尝试用x3替换<,但仍然存在问题。只追加jQuery库似乎会崩溃。。。

尝试将$('.element').hide();包装到$(function(){$('.element').hide();});

最新更新