我可以使用以下方法使div在同一页面上不可见:

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


在我的主页上是index.php。当用户单击按钮时,它使用ajax调用加载页面,并且url.php的内容显示在同一页面的index.php中

现在在url.php上有url.php,应在单击按钮后出现。

在index.php上

<body onload="show1()">


并且show1()是

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


url.php页面上的按钮

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


并且show()是

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


我也尝试通过在url.php上保留show1和show2,但是没有任何变化。
div不会变得不可见。

最佳答案

希望对您有帮助

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

<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" >

10-05 20:53
查看更多