Javascript 单选按钮标签在safari上单击计时

Javascript 单选按钮标签在safari上单击计时,javascript,php,jquery,html,safari,Javascript,Php,Jquery,Html,Safari,我在表格上记录了这种情况: <form id="boxselection" method="POST" action="select.php"> <label class="labels" for="boxtype"> <input type="radio" name="boxtype" value="3x80"> <img src="..."> </label> <labe

我在表格上记录了这种情况:

<form id="boxselection" method="POST" action="select.php">
    <label class="labels" for="boxtype">
        <input type="radio" name="boxtype" value="3x80">
        <img src="...">
    </label>
    <label class="labels" for="boxtype">
        <input type="radio" name="boxtype" value="4x80">
        <img src="...">
    </label>
</form>
<script>
    $('.labels').on('click',function() {
        $('#boxselection').submit();
    });
</script>

$('.labels')。在('click',function()上{
$(“#框选择”).submit();
});
在Chrome、Firefox和IE中,一切正常,在Safari中,PHP脚本不会收到任何POST值

一个有效的解决方法是通过以下方式修改javascript:

<script>
    $('.labels').on('click',function() {
        setTimeout( function() {
             $('#boxselection').submit();
        }, 1000);
    });
</script>

$('.labels')。在('click',function()上{
setTimeout(函数(){
$(“#框选择”).submit();
}, 1000);
});

这现在起作用了,我的问题是…为什么

首先,我认为您需要向单选按钮添加
id
值,以便标签与各自的单选按钮相关联。
for
属性将自身与表单元素的
id
相关联

<form id="boxselection" method="POST" action="select.php">
    <label class="labels" for="checkbox1">
        <input type="radio" name="boxtype" id="checkbox1" value="3x80">
        <img src="...">
    </label>
    <label class="labels" for="checkbox2">
        <input type="radio" name="boxtype" id="checkbox2" value="4x80">
        <img src="...">
    </label>
</form>

上述代码将在更改事件中为表单中的任何单选按钮触发表单提交。

奇怪,因为没有
setTimeut
method 8-)刚刚在没有“变通方法”的情况下尝试了您的代码,它在safari上起作用。你正在使用哪个操作系统?您使用的是哪一版本的safari?优胜美地在MacBook Air上预装的safari。我会检查一下确切的版本,然后让你know@Coulton我只是开玩笑:希望我的答案有帮助。我不知道标签在哪里与ID关联,我会试试你的解决方案。谢谢
$('form#boxselection').delegate('change', 'input[type="radio"]', function(e) {

    $('#boxselection').submit();
});