我有一個web窗體有幾個必填字段。當我提交表單時,我的CMS自動包含一些JS驗證以進行檢查。他們的驗證看起來是這樣的:檢查包含使用jQuery的警報,然後根據內容運行功能
function checkWholeForm88517(theForm) {
var why = "";
if (theForm.CAT_Custom_1) why += isEmpty(theForm.CAT_Custom_1.value, "First Name");
if (theForm.CAT_Custom_2) why += isEmpty(theForm.CAT_Custom_2.value, "Last Name");
if (theForm.CAT_Custom_3) why += isEmpty(theForm.CAT_Custom_3.value, "Email Address");
//etc.
if (why != "") {
alert(why);
return false;
}
}
當警報彈出它將包含文本,像這樣:
- Please enter First Name
- Please enter Last Name
- Please enter Email Address
我想要做的是運行一個if語句,看看是否警報包含- Please enter First Name
,如果是的話,做一些事情。
我試着這樣做:
window.alert = function(msg) {
if ($(this).is(':contains("- Please enter First Name")')) {
$(".error-msg").append('My Message...');
}
}
當然,這是行不通的,因爲我不太確定如何定位警報的msg
和檢查,看它是否包含文本。
我該怎麼做?