if (document.form1.elements[arg].value.substring(0,1)=="0")

解决方案 »

  1.   

    我用孟子E章的方法试了,但是出错:
    提示“'document.form1.elements[....].value'为空或不是对象“
      

  2.   

    好了,贴上来大家欣析一下用onblur="testprice('image_width');"调用function testprice(arg){  
    /*if (document.form.price.value.indexOf("0") > -1) {  */var s = document.getElementById(arg);
    if (s.value.substring(0,1) == "0" )
     {
    alert("不能用0开头");
    s.focus();
    return false;  
    }  
    else {  
    return true;  
    }  
    }
      

  3.   

    还有一种方法:
    onBlur="return testprice('image_width');"function testprice(arg)
    {  
    if (document.form1.elements[arg].value.substring(0,1)=="0")
    {
    alert("数据有误!");
    document.form1.elements[arg].focus();
    return false;  
    }  
    else
    {  
    return true;  
    }  
    }