jQuery - display : none not working
jQuery - display : none not working
我创建了一个网页,其中:
- 当用户单击按钮时,会打开一个iframe
- 我通过在css文件中创建iframe
display:none
来实现 - 单击按钮后,
display
属性变为inline
(通过jQuery)
但是,如iframe所示,还有一个close
按钮。单击时,iframe display
再次变为none
。但是,问题是它不起作用。简而言之,来自关闭按钮的display:none
不工作。
我的代码如下:
$(document).ready(function() {
$("#a_addupdate").click(function(){
$("#iframe_add_update").css(
"display" , "inline"
);
});
}); //This will show the iframe
$(document).ready(function() {
$("#close_frame").click(function(){
$("#iframe_add_update").css(
"display" , "none"
);
});
} //This will hide the frame
编辑:我还在iframe 中使用z-index:2
如果关闭按钮在iframe上,则应使用:
// code in your iframe
$(document).ready(function() {
$("#close_frame").click(function(){
$("#iframe_add_update", window.parent.document).css(
"display" , "none"
);
});
}
注意window.parent.document
位。这将使您的代码在父页上搜索#iframe_add_update
元素。
假设您的iframe
中也有jQuery
,并且它们都在同一域中,这将起作用。
您可以更新到此:
$(document).ready(function() {
$("#iframe_add_update").contents().find("#close_frame").click(function() {
$("#iframe_add_update").css("display", "none");
});
}); //This will hide the frame
$("#iframe_add_update").contents()
允许您查找iframe中的内容。
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working