简体   繁体   English

如何在ajax请求调用的页面上使div不可见

[英]how to make div invisible on page called by ajax request

I can make div visible invisible on the same page using: 我可以使用以下方法使div在同一页面上不可见:

document.getElementById("txtHint").style.display = "none";

By my main page is index.php . 在我的主页上是index.php Whe user click button it load tge page url.php using ajax call and content of url.php is appear on same page index.php in 当用户单击按钮时,它将使用ajax调用加载tge页面url.php并且url.php的内容显示在同一页面的index.php中

Now on url.php I have <div> which should appear after button click. 现在在url.php我有<div> ,它应该在单击按钮后出现。

on index.php 在index.php上

<body onload="show1()">

and show1() is 并且show1()是

function show1(){
   //alert("hi");
document.getElementById("txtHint").style.display = "none";
document.getElementById("d1").style.display = "none";
    }

Button on url.php page url.php页面上的按钮

<input type="submit" onclick="show2();" value="view div" > View Div </input>

and show() is 并且show()是

function show2(){
   //alert("hi");
document.getElementById("txtHint").style.display = "block";
document.getElementById("d1").style.display = "block";
    }

I also tried by keeping show1 and show2 on url.php but no change. 我也尝试通过在url.php上保留show1和show2,但是没有任何变化。 div does not become invisible anyhow. div不会变得不可见。

I hope it will help you 希望对您有帮助

index.php 的index.php

<span id='view_port'></span><br />
<input type="button" id="load_url" value="Load url.php" />

<script>
$("#load_url").click(function(){
    $.ajax({
        url:"url.php",
        success:function(response) {
            $("#view_port").html(response);
            $("#load_url").hide();
        }
    }); 
});

function show2() {
   //alert("hi");
    document.getElementById("txtHint").style.display = "block";
    document.getElementById("d1").style.display = "block";
}
</script>

url.php url.php

<div id='txtHint' style="display:none">This the div txtHint</div><br />
<div id='d1' style="display:none">This the div d1</div><br />
<input type="button" onclick="show2();" value="view div" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM