简体   繁体   English

复选框+标签jquery验证

[英]Checkbox + label jquery validation

How make to work message error in checkbox + label using jquery validation? 如何使用jQuery验证使复选框+标签中的工作消息错误?

I have this code: 我有以下代码:

html html

    <form id="myform">
 <input type="checkbox" id="term" name="term_1" /> 
   <label for="term">
      <div class="check"></div>
      Blabla Term.
   </label>
</form>
<a href="http://docs.jquery.com/Plugins/Validation" target="_blank"></a>

css 的CSS

input[type="checkbox"] {
    display:none;
}
input[type="checkbox"] + label .check {
    display:inline-block;
    width:16px;
    height:16px;
    margin:-3px 4px 0 0;
    vertical-align:middle;
    cursor:pointer;
}

input[type="checkbox"] + label .check {background:url(http://www.1.ligapariurilor.ro/imagini/sprite/radio-sprite.png) left top no-repeat;}

input[type="checkbox"]:checked + label .check{
    background:url(http://www.1.ligapariurilor.ro/imagini/sprite/radio-sprite.png) -16px top no-repeat;
}

And jQuery does not work 而且jQuery不起作用

$(document).ready(function () {

    $('#myform').validate({
        rules: {
            'term': {
                required: true
            }
        }
    });

});

Demo link: http://jsfiddle.net/AsuyC/17/ 演示链接: http : //jsfiddle.net/AsuyC/17/

I guess you mean 我想你是说

$(document).ready(function () {

    $('#myform').validate({
        rules: {
            '#term': {
                required: true
            }
        }
    }); 
});

I've posted an answer. 我已经发布了答案。 That's also a possibility for your issue. 这也是您遇到问题的可能性。 If you work on asp.net you can use the RequiredFieldValidator on your different control such as the following example : 如果您在asp.net上工作,则可以在其他控件上使用RequiredFieldValidator ,例如以下示例:

<tr>
<td>
<asp:RequiredFieldValidator runat=server
    ControlToValidate=txtName
    ErrorMessage="Identifier is required."> *
</asp:RequiredFieldValidator>
</td>
<td>User Identifier :</td>
<td><input type=text runat=server id=txtName></td>
</tr>

For the required fields you can use ValidationSummary property which display an " * " before required fields. 对于必填字段,您可以使用ValidationSummary属性,该属性在必填字段之前显示“ *”。

<asp:ValidationSummary runat=server
      headerText="there is error on this page/>

and don't forget the validation method : 并且不要忘记验证方法:

public sub OnSubmit(source as Object, e as EventArgs)
    if Page.IsValid then
    ' Some code
    end if
end sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM