<scrip>
function XXXBtn(type){
var mobile = "";
if(type == "1"){
if(document.getElementById("MobileOne")){
   mobile = document.getElementById("MobileOne").value;
}

}
if(type == "2" ){
if(document.getElementById("'MobileTwo'")){
  mobile = document.getElementById('MobileTwo').value;
}
}
if(type == "3"){
if(document.getElementById("MobileThree")){
  mobile = document.getElementById(MobileThree).value;
}
}
if(!checkMobilePhone(mobile)){
             //输入不正确
              return false;
}else{
            //带入参数,执行action方法
}
}
</script>我不知道js中是否有这样的写法,如果我的type不为空并且是在"1.2.3"中的一个值,那么红色部分能执行到吗?然后外面黄色的部分返回的不是一个对象吗,怎么能放在if()里面呢?这样的条件能成立吗?有哪位比较了解请不吝赐教.非常感谢.

解决方案 »

  1.   

    放在if中能执行的
    取不到的话就是false另外你黄色的字体不是很容易看清楚是什么,你不觉得吗?
      

  2.   

    可以执行到的。JS可以将其他类型转换为布尔型,
    对象类型转换为true,空对象null转换为false.
    其他的如:数值0转换为false,非0转换为true
    如if(10){ } if("asdd"){} if(new Date()){} 三个条件都成立都执行。
      

  3.   

    1、可以执行到,js判断字符串就是用==
    2、这种写法是对的,
    document.getElementById("MobileThree")
    如果存在id为MobileThree的HTML元素,即返回该元素,如果不存在,则返回空
    而if()条件,可以判断该元素是否存在
      

  4.   

    非常感谢各位的讲解,
    我想我已经明白了.thx