所以,我需要從主頁面關閉div,並從加載的頁面按鈕。jquery - 從加載頁面隱藏父div,
這是主要的網頁:
<div id="DIV1" style="display:none;"></div>
<div id="ShowPage1">Show 1</div>
<div id="ShowPage2">Show 2</div>
<script type="text/javascript">
$('#ShowPage1').click(function(){
$("#DIV1").load("test1.html");
$("#DIV1").show();
return false;
});
$('#ShowPage2').click(function(){
$("#DIV1").load("test2.html");
$("#DIV1").show();
return false;
});
</script>
這是test1.html
<div id="HideDIV1">HideDiv</div>
<script type="text/javascript">
$('#HideDIV1').click(function(){
$("#DIV1").hide();
return false;
});
</script>
第一部分,很好地工作,將其加載test1.html並顯示DIV1。 發佈時,我嘗試從test1.html隱藏它#HideDIV1,...只是不工作。
請幫忙。
是否來自test1.html的javascript實際運行?嘗試在其中放入一個alert()或console.log()來檢查它。 – Sebastianb
是的,帶有alert()工作 –
嘗試''('#HideDIV1')on('click',function(){$('#DIV1')。hide(); return false;});' – 2016-03-04 18:46:06