[英]Calling a function in the parent page from an element ajax - loaded into a div
[英]Remove html element from a page loaded as ajax response into div
我試圖在加載index.jsp頁面作為單擊regdata.jsp頁面上的登錄按鈕時的響應時,立即刪除id = regbutton的鏈接(我也想使它作為按鈕,請提供幫助)
regdata.jsp
<script> $(document).ready(function(){ $("button").click(function(){ $("#mainDiv").load("index.jsp"); $('#regButton').remove(); }); }); </script> </head> <body> <div id="mainDiv" class="units-row"> <h2>Thanks For registering!</h2> <button id="regLogin">Login Now</button> </div>
index.jsp
<body> <center> <s:actionerror /> <h1 id="login_title"></h1> <form action="checkLogin.action" method="post"> <p> <input type="text" id="username" name="username" placeholder="" > </p> <p> <input type="password" name="password" placeholder="" id="password"> </p> <label> <input type="checkbox" name="remember_me" id="remember"><label for="remember" id="rememberlbl"></label></label> </p> <input type="submit" class="btn-log" method="execute" key="label_login"> </form> <a href="registerLogin.action" id="regButton">Register</a> </center> </body>
jQuery的load函數帶有第二個或第三個參數-加載完成后要執行的回調函數。 因此,如果您希望按鈕僅在加載完成后才消失,則應將其代碼移動到該處理程序中:
$(document).ready(function(){
$("button").click(function(){
$("#mainDiv").load("index.jsp", function() {
$('#regButton').remove();
});
});
});
我可以看到一個簡單的解決方案
#regButton
{
display:none;
}
如果這還不夠,我也在研究一個jQuery解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.