通过单击表格单元格使用jquery提交表单

问题描述:

表单怎么可能只提交clickt表格单元格的输入"字段

How is this possible that the form submit only the "input" field of the clickt table cell

<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>

尝试一下:

<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,文本也会将事件传播到单选按钮.

I wrapped the text and the radio buttons between label that way, even if you use css to hide the radio buttons, the text would propagate the event down to the radio button.