2012-05-11 170 views
0

我有一些正常的div我的第一頁上:如何在第一頁,從另一個頁面隱藏div?

<div id="news"> 
      <div class="loginform"> 

       <div id="form_news"> 

       <form id="loginform" method="post" action="envianews.asp"> 
       <div id="news_campos"> 
        <input type="text" id="nome" name="nome" value="" title="Nome" placeholder="NOME" autocomplete="off" required /> 
        <input type="text" id="email" name="email" value="" title="Email" placeholder="EMAIL" autocomplete="off" required/> 
       </div> 
       <input type="submit" class="bt_news" name="submit" id="submit" value=""/> 
       <div id="news_response"></div> 
       </form>    

       </div> 

      </div> 
     </div> 

和我envianews.asp我有腳本來發送這些信息去數據庫。我想知道我需要做什麼,因爲當人點擊按鈕發送數據時,隱藏我的div news ...

+0

但提交到'envianews.asp'將刷新整個頁面,那麼,爲什麼你只想隱藏 '#news' DIV? –

+0

是的..我只想隱藏這些'#news' div在我的'index.html'頁面..例如.. – Preston

+0

所以你不希望整個頁面刷新,是嗎? –

回答

0
$(function(){ 
$("#submit").click(function(e){ 
    e.preventDefault(); 
    $.post("envianews.asp", { name: $("#nome").val(), email: $("#email").val() } ,function(data){ 
    $("#news_campos").hide(); // hide when we get the resonse from ajax call 
    }); 

}); 
}); 
+0

我喜歡你的例子......但我有一些問題:我用什麼來代替'{data:「yourdata」}'?我的輸入值 – Preston

+0

@Preston:是您的表單元素值。 – Shyju

+0

這樣?:'{data:「nome」,「email」}'(這些是我的表單元素的名稱)對不起,但我不太瞭解.. – Preston

0

這很簡單,在您發送數據並且想要隱藏您的div之後你要做的是:

document.getElementById('news').style.display = 'none' 
+0

沒有人會看到這個,因爲該頁面將被envianews.asp –

+0

取代envianews.asp我只有腳本記錄數據庫,所以在這些頁面I輸入的端部這樣的: ''這就是正確? – Preston

1

使用http://jquery.com/

,然後隱藏的div使用

$("#news").hide(); 

以及發送值數據庫使用Ajax

http://docs.jquery.com/Ajax

+0

沒有人會看到這個,因爲該頁面將被替換envianews.asp –

+0

可能他想隱藏它,直到請求被提交 – Imdad

+0

@Imdad thaths right ... !! – Preston

0
$(function(){ 
    $('#submit').click(function(){ 
     $('#news').hide(); 
    }); 
}); 

DEMO

相關問題