我試圖根據檢查哪個單選按鈕來更改html表單的操作。我想用jQuery來做到這一點。我有一些代碼,可以'找出它爲什麼不工作。有人可以幫助我讓這個代碼工作。依賴於單選按鈕的更改表單操作
HTML:
<form name=loginForm id='login' action='' method='post'>
<legend>Login</legend>
<input type='text' name='email' maxlength="100" placeholder="Email"/>
<input type='password' name='password' maxlength="100" placeholder="password"/>
<div class="checkBoxGroup">
<label for="Employer">Employer</label>
<input type="radio" name="status" id='employer' value="employer">
</div>
<div class="checkBoxGroup">
<label for="Staff">Staff</label>
<input type="radio" name="status" id='staff' value="staff">
</div>
<input type='submit' name='Submit' value='Login' />
</form>
的Javascript:因爲你的屬性設置爲checked
$(document).ready(function(){
$("input[name='status']").change(function(){
if($("#employer").prop("checked", true)){
$("#login").attr("action", "DB/employerVerification.php")
}
else{
$("#login").attr("action", "DB/userVerfification.php")
}
}
莫非這個問題是[問題]的重複(http://stackoverflow.com/questions/5451600/jquery-to-change-form-action) –
如果你願意用JS提交表單,你可以完全跳過這個部分。 或者只是使用document.getElementById('login')。action =「newaction」; –