submit form with jquery by click on table cell

柔情痞子 提交于 2019-12-12 06:59:02

问题


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>

回答1:


Try this:

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

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.



来源:https://stackoverflow.com/questions/26014630/submit-form-with-jquery-by-click-on-table-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!