1
如何在不檢查任何內容的情況下提交此內容,但在檢查一項內容時提交內容?它目前提交任一方式。我在這裏錯過了什麼?它會拋出我想要的錯誤時,什麼都沒有檢查「請檢查上面的選項之一」,但然後進入着陸頁。感謝您的任何幫助!保持單選按鈕形式提交時沒有檢查jquery
$(document).ready(function() {
$("#submitbutton").click(function() {
var none_answered = true;
$("input:radio").each(function() {
var name = $(this).attr("name");
if ($("input:radio[name]:checked").length == 0) {
none_answered = false;
}
});
if (none_answered == false) {
$('#texthere').html("Please check one of the options above");
}
})
});
<style type="text/css">
#texthere
{
color:red;
}
</style>
<body>
<form>
<input type="radio" name="refer" value="Strategic Communication" >Strategic Communication</br>
<input type="radio" name="refer" value="Journalism" >Journalism</br>
<input type="radio" name="refer" value="Communication Studies" >Communication Studies</br>
<div id="texthere"></div>
<input id="submitbutton" type="submit" value="submit" formaction="http://www.utah.edu/">
</form>
</body>