function save() {
var iframeID = $('iframe').attr('id');
var code = lazyMethod_get(iframeID, "form1", "txt_code");
var loa = lazyMethod_get(iframeID, "form1", "txt_loa");
var DWT = lazyMethod_get(iframeID, "form1", "txt_dwt");
var GrossTonnage = lazyMethod_get(iframeID, "form1", "txt_gross");
if (code == '')
{
Ext.Msg.alert("Code need to be fill in!");
}
else if (loa == '')
{
Ext.Msg.alert("LOA need to be fill in!");
}
else if (DWT == '')
{
Ext.Msg.alert("DWT need to be fill in!");
}
else if (GrossTonnage == '')
{
Ext.Msg.alert("Gross Tonnage need to be fill in!");
}
else
{
validateDuplicate(name);
this.up('window').close();
}
}
以上是我完成的代码,它会逐一提示。我需要它只验证一次,如果用户错过了2个文本框,它将提示错误一次,而不是两次。
答案 0 :(得分:7)
您可以通过使用OR运算符来执行此操作,但在这种情况下,您的警报消息将是通用的。
function save() {
var iframeID = $('iframe').attr('id');
var code = lazyMethod_get(iframeID, "form1", "txt_code");
var loa = lazyMethod_get(iframeID, "form1", "txt_loa");
var DWT = lazyMethod_get(iframeID, "form1", "txt_dwt");
var GrossTonnage = lazyMethod_get(iframeID, "form1", "txt_gross");
if (code == ''|| loa == '' || DWT == '' || GrossTonnage == '') {
Ext.Msg.alert("You need to fill all the text field");
}
else {
validateDuplicate(name);
this.up('window').close();
}
}
答案 1 :(得分:2)
您可以在变量中附加错误,然后警告变量,而不是在每种情况下发出警报。
var errors='';
if (code == '') {
errors+="Code need to be fill in!";
}
if (loa == '') {
errors+="LOA need to be fill in!";
}
在所有条件检查后是否有任何错误然后提醒
if(errors.length>0){
Ext.Msg.alert(errors);
}
这是javascript示例。同样可以应用于C#也
答案 2 :(得分:1)
尝试if语句如下: if(x =="&& y =="&& z =") { //做东西 } 或者这个
import UIKit
import Foundation
class XyzTableViewCell: UITableViewCell
{
@IBOutlet weak var phoneNumber: UILabel!
var touchContact : String = ""
var myCell: MyCellData! {
didSet {
self.updateUI()
}
}
func updateUI()
{
touchContact = vicarCell.phone_no
//Tap Gesture
tapGestureAddonView()
}
//MARK:- Tap to Call and Open Email
func tapGestureAddonView(){
let contacttap = UITapGestureRecognizer(target: self, action:("contactTapped"))
contacttap.numberOfTapsRequired = 1
phoneNumber!.userInteractionEnabled = true
phoneNumber!.addGestureRecognizer(contacttap)
}
func contactTapped() {
// do something cool here
print("contactTapped")
print(touchContact)
dispatch_async(dispatch_get_main_queue())
{
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "telprompt://\(self.touchContact)")!){
UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(self.touchContact)")!)
}
else{
//showAlert("Info",message: "Your device could not called" ,owner: self)
}
}
}