简体   繁体   English

从作为Ajax响应加载到div的页面中删除html元素

[英]Remove html element from a page loaded as ajax response into div

I am trying to remove a link(I want to make this as button please help in that too) with id=regbutton as soon as my index.jsp page is loaded as a response on clicking login button on regdata.jsp page 我试图在加载index.jsp页面作为单击regdata.jsp页面上的登录按钮时的响应时,立即删除id = regbutton的链接(我也想使它作为按钮,请提供帮助)

regdata.jsp 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 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"> &nbsp;&nbsp; </form> <a href="registerLogin.action" id="regButton">Register</a> </center> </body> 

The jQuery's load function takes a second or third parameter - a callback function to execute when loading is done. jQuery的load函数带有第二个或第三个参数-加载完成后要执行的回调函数。 So if you want the button to disappear only when the load completes you should move your code for it into that handler: 因此,如果您希望按钮仅在加载完成后才消失,则应将其代码移动到该处理程序中:

$(document).ready(function(){
    $("button").click(function(){
        $("#mainDiv").load("index.jsp", function() {
          $('#regButton').remove();
        });
    });
});

I can see a simple solution 我可以看到一个简单的解决方案

#regButton
{
 display:none;
}

If this ain't sufficient i am working on a jquery solution as well 如果这还不够,我也在研究一个jQuery解决方案

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

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