2014-02-24 101 views
0

如何使工作邮件错误复选框+标签使用jquery验证?复选框+标签jquery验证

我有这样的代码:

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

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; 
} 

和jQuery不起作用

$(document).ready(function() { 

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

}); 

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

+0

什么是你想在这里做 –

+0

我尝试把错误信息时,未选中 – golaz

回答

0

我猜你的意思是

$(document).ready(function() { 

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

不起作用....... – golaz

0

我已经张贴一个答案。这也是你的问题的可能性。 如果您在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> 

对于必填字段,您可以使用它显示一个“*”之前,需要领域的ValidationSummary财产。

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

,不要忘记验证方法:

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

我使用wordpress。你能给我演示一下我的例子吗? – golaz

+0

这里你有一个很好的示例:http://ramanisandeep.wordpress.com/2010/02/10/checkboxlist-validation-using-jquery/ –

+0

好的,我会尝试... – golaz