一旦我的 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();
});
});
});
关于javascript - 从作为ajax响应加载到div中的页面中删除html元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31177027/