Py学习  »  Jquery

如何使用jQuery选择要与.empty()一起使用的输入?

BlueDogRanch • 4 年前 • 601 次点击  

在下面的HTML中,如何使用jQuery .empty 删除 <div class="password-link"> 以及里面的一切 href link ,文本 Log in 以及 </a> -以及闭幕式 </div> ?

我想用

jQuery('#lostpasswordform input#wp-submit').empty('password-link');

但我不能用正确的方式选择输入或表单。

<form name="lostpasswordform" id="lostpasswordform" action="http://localhost/~user/wp-core/wp-login.php?action=lostpassword" method="post">
  <input type="hidden" name="redirect_to" value="">
     <p class="submit">
        <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="">
// Remove this:
    <div class="password-link"><a href="http://localhost/~user/wp-core/wp-login.php">Log in</a></div>

    </p>
</form>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52562
 
601 次点击  
文章 [ 3 ]  |  最新文章 4 年前
Asheesh Banga
Reply   •   1 楼
Asheesh Banga    4 年前

.empty()删除子节点和内容。因此,您要移除的div应该包装在另一个div上,您可以对该父div调用.empty()方法。

Anonymous
Reply   •   2 楼
Anonymous    4 年前

你可以这样试试

$('#lostpasswordform input#wp-submit').on("click", function(){
  var $passwordlink = $(".password-link");
  $passwordlink.empty();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form name="lostpasswordform" id="lostpasswordform" action="http://localhost/~user/wp-core/wp-login.php?action=lostpassword" method="post">
  <input type="hidden" name="redirect_to" value="">
     <p class="submit">
        <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="">
// Remove this:
    <div class="password-link"><a href="http://localhost/~user/wp-core/wp-login.php">Log in</a></div>

    </p>
</form>
Tân
Reply   •   3 楼
Tân    4 年前

确保要删除该元素或清除其内容

$('.password-link').empty() 将返回:

<div class="password-link"></div>

虽然 $('.password-link').remove() 将移除/删除该元素 .password-link