0

我有一个生成 2 个单选按钮的 wordpress 插件。对于构象,我想显示在下一页上单击的最后一个单选按钮的值。

我想我会用 cookie 和 jquery 来做到这一点。我得到的是这个:

<script type='text/javascript'>
    var verzend = $.cookie("verzend")
    $('input:radio[value="OrderWeight-0]').click(function () {
        $.cookie('verzend', 'verzenden')
    });
    $('input:radio[value="OrderWeight-1]').click(function () {
        $.cookie('verzend', 'afhalen')
    });
</script>

不幸的是,它不起作用。谁能指出我正确的方向?

4

1 回答 1

0

You should try with the change event, more adapted to radio input.

<script type='text/javascript'>
    var verzend = $.cookie("verzend")
    $('input:radio').on('change', function() {
        if ($(this).val() === "OrderWeight-0") {
            $.cookie('verzend', 'verzenden')
        } else {
            $.cookie('verzend', 'afhalen')
        }
    });
</script>
于 2012-07-16T12:05:45.767 回答