问问题
80 次
4 回答
1
我认为您必须要么查找表单提交,要么必须初始化更改:
$("#age").change(function(){
$("#age").after('<span class="register-error age-error">age</span>');
}).change(); // <----this way
你需要这种html:
<select id="age">
<option value="">choose</option> //<-----a blank value of the select
小提琴
于 2013-03-12T16:45:36.183 回答
0
Have the required field already on your HTML page, but has a hidden element. Perhaps right under the form.
Use jQuery to check if the user has left your form element blank after they haved submited the form. Use jQuery's Submit Method to setup the base logic for your form. Then incorporate a conditional statement inside the method something like this....
The JS:
if($(this).val() == "") {
showRequiredBoxEmail(); //this function shows the required message
}
else {
hideRequiredBoxEmail(); //this function hides the required message
}
于 2013-03-12T16:48:55.793 回答
0
问题在于,对于您当前的 HTML,始终选择一个选项(18
始终选中)。您需要添加一个具有空值的选项:
<select id="age">
<option value="">Please select an option</option>
<option value="18">18</option>
<option value="19">19</option>
...
...
<option value="65">+65</option>
</select>
于 2013-03-12T16:42:47.863 回答
0
试试这个:
$("#form-id").submit(function() {
if ($("#age").val() == "") {
$("<span class='register-error age-error'>age</span>").insertAfter("#age");
}
});
于 2013-03-12T16:42:54.150 回答