[英]If statement giving incorrect results.
我有這個代碼來向網站添加列表(SharePoint)。 我添加了一個條件,提醒用戶填寫表單時是否填寫錯誤。 當XML中存在錯誤時,我通常使用.find(“errorstring”)。 現在我的代碼不斷向我發出警告,即使我查看XML錯誤字符串不存在時也會出現錯誤。 這是代碼:
function createList(){
if(!siteUrl){
alert("You must first select a site");
return;
}
var listName = $('#listName');
var listDesc = $('#listDesc');
var listTemp = $('#listTemplate');
var siteLists = $('#web_siteLists');
console.log(siteUrl+" - "+listName+" - "+listDesc+" - "+listTemp);
$().SPServices({
operation:"AddList",
webURL: siteUrl,
listName: listName.val(),
description: listDesc.val(),
templateID: listTemp.find(':selected').val(),
completefunc: function(xData, Status){
if($(xData.responseXML).find('errorstring')){
alert('Please fill form correctly');
return;
}else{
alert(listName+" created.");
siteLists.empty();
RefreshSiteList(siteUrl);
listName.val('');
listDesc.val('');
listTemp.val('default');
}
}
});
}
XML響應: http : //jsfiddle.net/f6tRw/
我想我的條件可能沒有說明:
if($(xData.responseXML).find('errorstring')){alert('請填寫表格正確'); 返回; }
用這個:
if($(xData.responseXML).find('errorstring').length > 0){
當沒有匹配時, .find()
返回的.find()
是真的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.