我已經創建了一個添加電子郵件方法(jquery)來驗證收件人文本框中的多個電子郵件。當prototype.js沒有在頁面上聲明時它工作正常。爲了擺脫$衝突,我還加入了$ noconflict()方法度量度量。除了收件人電子郵件驗證字段之外,其他字段驗證在這種情況下正在工作。 AS根據我的發現「jQuery.validator.methods.email.call(this,value,element)」頁面的第50行不起作用,因此該方法未觸發。我也需要調用prototype.js。請參閱以下代碼以獲得更清楚的理解.......提前致謝。如果我們在頁面上調用prototype.js,multiemail驗證方法不起作用。
請參考下面的代碼: 多電子郵件驗證
變種JQ = jQuery.noConflict();
JQ(文件)。就緒(函數(){
// Handler for .ready() called.
JQ("#email-form").validate({
rules : {
email : {
required : true,
email : true
},
recipientEmail : {
multiemail: true,
required : true
// email : true
}
},
messages: {
email: {
required: "Please enter your email address.",
email: "Please enter a valid email address"
},
recipientEmail: {
multiemail: "One or more of your recipient email addresses needs correction.",
required: "Please enter the recipient's email address."
//email: "Please enter a valid email address"
}
}
});
});
JQ.validator.addMethod( 「multiemail」,函數(值,元素){ 如果(this.optional(元件))//返回(可選) 返回true; // var emails = value.split S *,\ S *」, 「GI」));
valid = true;
maxEmaillength = emails.length;
for(var i in emails)
{
value = emails[i];
valid = valid && jQuery.validator.methods.email.call(this, value, element);
// Maximum email length validation
if(maxEmaillength > 5)
{
JQ('label.error:first').html("Please enter only 5 mail IDs at a time");
JQ('label.error:first').css(display, block);
setTimeout(alert("Please enter only 5 mail IDs at a time"), 5);
}
}
return valid;
}, 'One or more email addresses are invalid');
</head>
<body>
<form action="" method="get" name="email-form" id="email-form">
<label for="email">email</label>
<input type="text" name="email" id="email" style="width:200px" />
<br />
<label for="recipientEmail">Recipient Email</label>
<input type="text" name="recipientEmail" id="recipientEmail" style="width:500px" /><br />
<input type="submit" name="Submit" id="Submit" value="Submit" />
</form>
</body>
</html>
我在我的測試結束。它正在工作。如果有的話,請給出你的改進建議。 – 2010-09-28 04:11:35