[英]JQuery Replacewith DIV does not load
因此,我有登錄頁面,如果他們單擊按鈕進行注冊,我將嘗試用注冊表單替換登錄表單。
目前我有:
<script>
$(document).ready(function(){
$("button").click(function(){
$("w").replaceWith(function(n){
return "DIV HERE BUT DIVS DO NOT WORK";
});
});
});
</script>
</head>
<body>
<div class="col-lg-6 col-sm-6 col-xs-12 social-login">
<a href="#" class="google_button login_btn">
<i aria-hidden="true" class="fa fa-google-plus-square"></i><span>Continue with Google</span>
</a>
<a href="#" class="facebook_button login_btn">
<i aria-hidden="true" class="fa fa-facebook-square"></i><span>Continue with Facebook</span>
</a>
<a href="#" class="twitter_button login_btn">
<i aria-hidden="true" class="fa fa-twitter-square"></i><span>Continue with Twitter</span>
</a>
<a href="#" class="linkedin_button login_btn">
<i aria-hidden="true" class="fa fa-linkedin-square"></i><span>Continue with Linkedin</span>
</a>
<a href="/signup" class="email_button login_btn">
<i aria-hidden="true" class="fa fa-linkedin-square"></i><span>Continue with Email</span>
</a>
<button>Continue With Email</button> <span class="light_grey">By signing up you indicate that you have read and agree to the <a target="_blank" href="#">Terms of Service</a> and <a target="_blank" href="#">Privacy Policy</a>.</span>
</div>
<form action="" class="signin_form" method="post">
<w><div class="title">Login</div></p></w>
<div class="form_inputs">
<div class="form_column">
<input type="text" name="username" id="username" placeholder="Email" value="" class="username">
</div>
<div class="form_column">
<input type="password" name="password" id="password" placeholder="Password" value="" class="password">
</div>
<div class="form_column">
<span><div class="remember_checkbox"><input type="checkbox" value="" name="remember_checkbox" checked="checked" class="remember_checkbox">Remember Me</div></span><input type="submit" value="Sign In" name="send" class="btn btn-primary pull-right" />
<span><a href="#" class="forgot_password">Forgot Password?</a></span>
</div>
</div>
</form>
</body>
我想將表單類signin_form替換為:
<form action="" class="signup_form" method="post">
<div class="title">Sign up!</div>
<div class="form_inputs">
<div class="form_column">
<input type="text" name="email" id="email" value="<?php echo $dd; ?>" class="email" placeholder="Email">
</div>
<div class="form_column">
<input type="text" name="username" id="username" placeholder="First Name" value="<?php echo $_POST['username']; ?>">
</div>
<div class="form_column">
<input type="password" name="password" id="password" placeholder="Password" value="" class="password">
<div class="form_column">
<input type="password" id="confirm_password" name="confirm_password" placeholder="Confirm Password" value="" class="confirm_password">
</div>
<div class="form_column">
<span><a href="/login" class="forgot_password">Already Have an Account?</a></span><input type="submit" value="Sign Up" name="send" class="btn btn-primary pull-right" />
</div>
</div>
</form>
使用我目前正在使用的replaceWith,如果它不包含div,則可以替換一行;如果放入div,則不再加載。
我認為replaceWith不是實現所需功能的正確方法,這不是因為您不能,而是因為您隨后需要動態創建新表單,並且必須將所有事件掛接到新表單中的元素上。 相反,您應該執行以下操作
這將是實現您所追求的那種功能的最簡單,最安全的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.