2014-02-24 99 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