2014-09-24 77 views
-1

通過點擊提交表單與jQuery這是如何實現的形式提交clickt表格單元格中只有「輸入」欄在表格單元格

<form id="switch" method="POST"> 
    <table> 
     <tr> 
      <td>some content<input type="hidden" name="switch_value" value="1"></td> 
      <td>some content<input type="hidden" name="switch_value" value="2"></td> 
      <td>some content<input type="hidden" name="switch_value" value="3"></td> 
      <td>some content<input type="hidden" name="switch_value" value="4"></td> 
      <td>some content<input type="hidden" name="switch_value" value="5"></td> 
     </tr> 
    </table> 
</form> 
+1

您可以禁用其他未被點擊的輸入,然後提交表單。 – Spokey 2014-09-24 10:35:01

回答

1

試試這個:

<form id="switch" method="POST"> 
    <table> 
     <tr> 
      <td><label>some content<input type="radio" name="switch_value" value="1"></label></td> 
      <td><label>some content<input type="radio" name="switch_value" value="2"></label></td> 
      <td><label>some content<input type="radio" name="switch_value" value="3"></label></td> 
      <td><label>some content<input type="radio" name="switch_value" value="4"></label></td> 
      <td><label>some content<input type="radio" name="switch_value" value="5"></label></td> 
     </tr> 
    </table> 
</form> 
<script> 
$(document).ready(function(){ 
    $('#switch input[type="radio"]').change(function(){ 
    $('#switch').submit(); 
    }); 
}); 
</script> 

我包文本和label之間的單選按鈕,即使您使用css隱藏radio buttons,文本也會將事件傳播到單選按鈕。

+0

這個工程,但是,我有問題,單選按鈕需要在表中額外的空間,即使我用CSS隱藏按鈕 – 2014-09-24 13:35:46

+0

如果你使用CSS來隱藏它們,'display:none;寬度:0「,那麼他們真的不應占用任何空間。 – Peter 2014-09-25 10:19:06

+0

謝謝,就是這樣:D – 2014-09-25 13:20:57