我用插件從MVC視圖http://jqueryvalidation.org/和改性如下:
注:當使用下拉項 - >值:0,文本: - 請選擇
- >添加自定義所需的類型
//====find "message {: ..."
messages: {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",....
//====modify to
messages: {
noDefaultVal: "This field is required.", //<-- modified
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",....
- >添加定製所需的方法
//====and find "methods: {: ..."
methods: {
// http://docs.jquery.com/Plugins/Validation/Methods/required
required: function(value, element, param) {
// check if dependency is met
if (!this.depend(param, element)) {....
//====modify to
methods: {
noDefaultVal: function (value, element, param) {
return this.optional(element) || value != param;
},
// http://docs.jquery.com/Plugins/Validation/Methods/required
required: function(value, element, param) {
....
- >對網頁腳本
$("#frmSave").validate({
//set required fields
rules: {
ITEM_TYPE: {
required: true ,
noDefaultVal: "0"
}
}
});
方面。
非常感謝您的快速回復! – koko 2010-10-13 09:41:14
嗨,我需要這個能夠顯示自定義消息(不:「請選擇一個值!」)。我將如何通過它呢?任何幫助將非常感激!。 – Anil 2011-11-30 17:24:44
您只需更改文字「請選擇一個值!」去別的,不是嗎? – koko 2012-06-25 09:19:01