<input   type="button"   name="button"   id="button"  onclick="this.form.submit();" >
我想在onclick中判断一下,当 document.getElementById('testTab11').getElementsByTagName('input').length 大于1时,才执行 this.form.submit(); 否则 提示一下,但一直说语法错误,求助啊~~~一直不擅长JS ,另外分不多了T_T

解决方案 »

  1.   

    不用onclick,用onsubmit,在onsubmit调用的程序里返回true 则 form 提交,返回false则不提交.
      

  2.   

    <input type="submit" name="button" id="button" onclick="return chkdata();" >
    <script>
    function chkdata()
    {
      if (document.getElementById('testTab11').getElementsByTagName('input').length<=1)
      {
         alert("请输入");
         return false;
    }
    esle
    {
       return true;
    }
    }
    </script>
      

  3.   


     <form id="form1" name="form1" action="xx.php" onsubmit="return checkForm();"> 添加了吗 ?报什么错 。
      

  4.   

    <input type="button" name="button" id="button" onclick="return chkdata();" >
    <script>
    function chkdata()
    {
      if (document.getElementById('testTab11').getElementsByTagName('input').length<=1)
      {
      alert("请输入");
      return false;
    }
    else
    {
      this.form.submit();
    }
    }
    </script>ls的笔误了。
    else写成esle了。。
      

  5.   

    不行   onsubmit="this.form.submit();" 表单无法提交  form里已经 onSubmit="return false;" 了 因为有其他按钮在,其他按钮不能有提交操作
      

  6.   


     <form name="form1" id="form1" action="attractions_DIY_num3.php"  method="post" onSubmit="return false;">
                    <div class="onLine_DIYLine_2Right">
                      
                        <div class="onLine_DIYLine_2RightTopText">
                            <input type="hidden" value="<?php echo $adult;?>" name="adult"  id="adult"  onKeyUp="this.value=this.value.replace(/\D/g,'')"/>
                            <input type="hidden" name="children" id="children"  maxlength="3" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<?php echo $children;?>"/>
                            <input type="hidden" name="days" id="days"  maxlength="3" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<?php echo $num;?>"/>
    <input type="hidden" name="title" id="title"  maxlength="3" value="<?php echo $title;?>"/>

    <?php if($type==1){ ?>
       
       <input type="hidden" name="type" id="type"  maxlength="3" value="1"/>
         <?php }?>
                        </div>         <?php
                   for($n=1;$n<=$num;$n++)
                   {
                      if($n==1){
                ?>
                   <div id="con_one_1">
                   <?php }else{?>
                    <div id="con_one_<?php echo $n;?>" style="display:none">
                    <?php }?>                    <div class="clear">
                        <div><span class="FB FZ14">第<?php echo $n;?>上午</span>(9:00-12:00)</div>                    <div class="DIYLine_2RightChangeBox">                       <?php
       if($type == 1){
       $sql = "select * from dede_trip_son where mtid =".$id." and numhowlong = ".$n;

       $rs = $mysql->query($sql);
       }
       ?>
                          <table  id="testTab1<?php echo $n;?>" name="testTab1<?php echo $n;?>"  width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="65%" height="25" align="center"><strong>景点名称</strong></td>
                              <td width="20%" height="25" align="center"><strong>交通方式</strong></td>
                              <td width="15%" height="25" align="center"></td>
                            </tr>

    <?php 
       if($type == 1){
       
       while($row = $mysql->fetch_array($rs)){
        $morningnum = substr_count($row["morningtrip"],",")+1; 


    $morningtrip =  explode(",",$row["morningtrip"]);
    $tid = 19;
    for($m=0;$m<$morningnum;$m++){
    ?>

    <tr id="str<?php echo $n;?><?php echo $tid;?>"  align="center">
                              <td width="65%" height="25" align="center"><input name= s_attractions<?php echo $n.$tid;?> type="text"  readonly id= s_attractions<?php echo $n.$tid;?> value="<?php echo $morningtrip[$m];?>" /></td>
                              <td width="20%" height="25" align="center"><select name= s_traffic<?php echo $n.$tid;?> id= s_traffic<?php echo $tid;?> ><option value='其它'>其它</option><option value='自驾'>自驾</option><option value='公交'>公交</option><option value='自行车'>自行车</option></select></td>
                              <td width="15%" height="25" align="center"><button onclick="moveTr('<?php echo $tid;?>','<?php echo $n;?>','1');" >移除</button></td>
                            </tr>
    <?php $tid++;}} } ?>
                          </table>
                          <center>
                            <input name="button" type="button" value="添加景点" class="DIYLine_2RightChangeBoxBotton" onclick="addTr(<?php echo $n;?>,1);"/>
                          </center>
                        </div>
                      </div>
                      <div></div>
                      <div class="clear">
                        <div><span class="FB FZ14">第<?php echo $n;?>下午</span>(12:00-18:00)</div>                    <div class="DIYLine_2RightChangeBox">
                          <table id="testTab2<?php echo $n;?>" name="testTab2<?php echo $n;?>" width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="65%" height="25" align="center"><strong>景点名称</strong></td>
                              <td width="20%" height="25" align="center"><strong>交通方式</strong></td>
                              <td width="15%" height="25" align="center"></td>
                            </tr>

    <?php 
       if($type == 1){
       $sql_f = "select * from dede_trip_son where mtid =".$id." and numhowlong = ".$n;

       $rs_f = $mysql->query($sql_f);
       while($row_x = $mysql->fetch_array($rs_f)){
       
       
    $afternoonnum = substr_count($row_x["afternoontrip"],",")+1; 

    $afternoontrip = explode(",",$row_x["afternoontrip"]);
    $tid = 19;

    if(!empty($row_x["afternoontrip"])){
    for($f=0;$f<$afternoonnum;$f++){
    ?>

    <tr id="xtr<?php echo $n;?><?php echo $tid;?>"  align="center">
                              <td width="65%" height="25" align="center"><input name= x_attractions<?php echo $n.$tid;?> type="text"  readonly id= x_attractions<?php echo $n.$tid;?> value="<?php echo $afternoontrip[$f];?>" /></td>
                              <td width="20%" height="25" align="center"><select name= x_traffic<?php echo $n.$tid;?> id= x_traffic<?php echo $tid;?> ><option value='其它'>其它</option><option value='自驾'>自驾</option><option value='公交'>公交</option><option value='自行车'>自行车</option></select></td>
                              <td width="15%" height="25" align="center"><button onclick="moveTr('<?php echo $tid;?>','<?php echo $n;?>','2');" >移除</button></td>
                            </tr>
    <?php $tid++;}}} } ?>


                          </table>
                          
                          <center>
                            <!--<button onclick="addTr(<?php echo $n;?>,2);" style="width:85px;height:25px; background:#333; font-weight:bold;" >添加景点</button>-->
                          <input name="button" type="button" value="添加景点" class="DIYLine_2RightChangeBoxBotton" onclick="addTr(<?php echo $n;?>,2);"/>
                          </center>
                        </div>                  </div>
                      <div class="clear">
                        <div><span class="FB FZ14">晚上</span></div>
                        <div>
                          <ul>
                            <li> 请选择酒店                          <select style="width:150px;" name="select<?php echo $n;?>" id="select<?php echo $n;?>">
                                  <option>无</option>
                                      <?php
                                     $rs=$mysql->query("select * from dede_archives  where  typeid  = 40 ");
                                     while($row = $mysql->fetch_array($rs))
                                    { ?>
                                  <option><?php echo $row["title"];?></option>
                                  
                                  <?php }?>
                                </select>
                            </li>
                          </ul>
                        </div>
                      </div>
      <div class="clear"></div>
                      </div>
                      
                       <?php }?>
                      <div class="onLine_DIYLine_2Button">
                       <input name="Submit2" type="button" class="onLine_DIYLine_2Button_2" onFocus="blur()" onClick="javascript:history.go(-1)" />
                       
                        
                      </div>
                      <div class="onLine_DIYLine_2Button">
                                          <input   type="button"   name="button"   id="button"   class="onLine_DIYLine_2Button_1"onclick="this.form.submit();" >
        
                      </div>
                    </div>
                    
                  </div>
                  </form>
    addTr() 是一个控制弹出子窗口的JS函数,在子窗口上选择值后,按钮确定,传递给父窗口上显示,但在子窗口上点确定时,发生了 火狐会直接提交表单的情况,所以在 form里 onSubmit="return false;" 然后
    button 里 onclick="this.form.submit();"避免自动提交,现在需要判断提交时有没有在子窗口选择过
    所以要加个判断 
      

  7.   

    onclick="this.form.submit();" 这样肯定就直接提交上去了 。
    你写个方法 ,判断下你的条件 。
    符合的再 document.getElementById("form1").submit();
      

  8.   

    干脆直接写个主方法,onclick="whatLength(this.value)" 
    function whatLength(x)
    {
     if (x>1)
       submit();
     else
       return false;
    }
      

  9.   

      if (document.getElementById('testTab11').getElementsByTagName('input').length<=1)这啥意思?获取ID不就完了,又接着获取tagName为input的所有元素你把 “ getElementsByTagName('input'). ”删掉试试
      

  10.   


    onclick="if(document.getElementById('testTab11').value.length<=1){alert('请xxxxxxxxx');return false;}this.form.submit();"