<html>
<head>
</head>
<body>
   <form name="form1" id="form1" method="post" action="MyShowInvoke.jsp">
   <Table id="Table1" width="100%" BORDER="1">
   <tr width="100%">
   <td width="50%" align="center" >
   <input type="text" name="ServiceNameText1" id="ServiceNameText1" 
value="j" size="50">
   </td>
   <td width="20%" align="center" >
   <input type="button" name="doService" value="执行服务!" onClick="checkNull();">
   </td>
   </tr>
   </Table>
<script language="javascript">
   function checkNull(){
   if (document.form1.Table1.tdtext1.ServiceNameText1.value="")
      {alert("请选择一个服务!");}
   }
   </script>
</form>
</body>
<html>为什么:document.form1.Table1.tdtext1.ServiceNameText1.value 老是说对象为空或不存在?

解决方案 »

  1.   

    document对象使用的不对,找不到对象啊
      

  2.   

    var txtObj = document.getElementById("ServiceNameText1");
    txtObj就是你的text框,你可以根据属性做你想做的
    这个函数的大小写可能不对,你自己查一下吧
      

  3.   

    不过你在操作之前最好if(txtObj != null){}这样至少不会有js错误
      

  4.   

    alert(document.form1.ServiceNameText1.value);if(document.getElementById("ServiceNameText1").value==""){alert("请选择服务!");}
    两种写法都正确