jquery easyui校正select下拉式清單值是否為空白的問題

來源:互聯網
上載者:User

標籤:style   使用   width   類   問題   cti   

屬性名稱 類型 描述 預設值
required布爾定義文本域是否為必填項false
validType字串定義欄位的驗證類型,比如email, url, etc.null
missingMessage字串當文字框為空白時提示的文本資訊This field is required.
invalidMessage字串當文字框內容不合法時提示的文本資訊null

required只表示文字框中是否有內容,easy ui的select框渲染完後 會自動添加一個文字框用於輸入,如下所示:
<span class="combo" style="width: 198px; height: 20px;"><input type="text" class="combo-text validatebox-text validatebox-invalid" autocomplete="off" style="width: 176px; height: 20px; line-height: 20px;"><span><span class="combo-arrow" style="height: 20px;"></span></span><input type="hidden" class="combo-value" name="state" value=""></span>

此時如果required=true,你清空此文字框,則會報 必須有內容的異常; 即此時驗證的是<option></option>中間的內容是否為空白

你可以加editable="false" 不允許編輯

你現在是想校正 <option value="">是否為空白,可以這樣

1、註冊自訂的validateType
$.extend($.fn.validatebox.defaults.rules, { 
selectValueRequired: { 
validator: function(value,param){ 
console.info($(param[0]).find("option:contains(‘"+value+"‘)").val());
return $(param[0]).find("option:contains(‘"+value+"‘)").val() != ‘‘; 
}, 
message: ‘select value required.‘ 
} 
});


2、使用

<select
id="test"
class="easyui-combobox"
name="state"
style="width:200px;"
required="true"
validType="selectValueRequired[‘#test‘]"
>
   <option value="">test1</option>  
   <option value="2">test2</option>  
   <option value="3">test3</option>
</select>

selectValueRequired[‘#test‘] 表示驗證類型 和 驗證的組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.