[英]JQuery remove div not working in Internet Explorer
I'm not really a javascript/jquery coder, I have a very simple code to remove a div that's not working in IE 我不是一个真正的javascript / jquery编码器,我有一个非常简单的代码来删除一个不能在IE中工作的div
I'm using this in a Joomla page, so I call it like this: 我在Joomla页面中使用它,所以我这样称呼它:
$document->addScript("http://code.jquery.com/jquery-latest.js");//adiciona jquery
And than, in the body document: 而且,在身体文件中:
<script>
setTimeout(function() {
$("#yourDiv").remove();
}, 50000);
</script>
FireFox and Chrome are (as always) ok. FireFox和Chrome(一如既往)还可以。 Can someone point out my mistake please?
有人可以指出我的错误吗? Thanks a lot :)
非常感谢 :)
EDITED * ** * ** * ** * ** 已编辑* ** * ** * ** * **
I've tryied also with this code no jquery, but always not working in IE (9) 我也试过这个代码没有jquery,但总是不在IE中工作(9)
<script>
setTimeout('yourFunction();', 5000);
function yourFunction(){
var div = document.getElementById("yourDiv");
div.parentNode.removeChild(div);
}
</script>
Maybe this addScript doesn't work. 也许这个addScript不起作用。 Check if jQuery is loaded:
检查是否加载了jQuery:
alert(typeof($));
This alert message would return function or undefined . 此警报消息将返回函数或未定义 。
I had this same issue and eventually realized I was using .append to a div and mistakenly also adding my own closing div. 我有同样的问题,并最终意识到我正在使用.append到div,并错误地添加了我自己的结束div。
IE is very picky about having elements nested properly. 关于正确嵌套元素,IE非常挑剔。
I tested this in internet explorer and firefox, works in both. 我在Internet Explorer和Firefox中测试了这个,两者都适用。
<html>
<head>
<script type="text/javascript">
var p = {
onload: function() {
setTimeout(
function() {
var div = document.getElementById("myDiv");
div.parentNode.removeChild(div);
},
3000
);
}
}
</script>
</head>
<body onload="p.onload()">
<div id="myDiv" style="height: 50px; width: 50px ;background-color: grey;"></div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.