点击弹出一个单选按钮

时间:2015-01-09 12:04:03

标签: javascript php popup radio-button

我有两个单选按钮,表格如下

<input name="exservman" id="yes" value="1" <?php echo $exserY;?>  type="radio" data-title="Ex-servicemen" class="btn btn-primary my-popover">Yes
 <input type="radio" name="physical" id="phyno" value="0">No

我遇到的问题是虽然在选择单选按钮弹出窗口时出现但我想通过单击否单选按钮关闭它。

这是JS

var $elements = $('.my-popoverr');
$elements.each(function () {
    var $element = $(this);

    $element.popover({
        html: true,
        placement: 'top',
        container: $('body'), 
        content: $('#content').html()
    });

    $element.on('shown.bs.popover', function () {
        var popover = $element.data('bs.popover');
        if (typeof popover !== "undefined") {
            var $tip = popover.tip();
            zindex = $tip.css('z-index');

            $tip.find('.close').bind('click', function () {
                popover.hide();
            });

            $tip.mouseover(function () {
                $tip.css('z-index', function () {
                    return zindex + 1;
                });
            })
                .mouseout(function () {
                $tip.css('z-index', function () {
                    return zindex;
                });
            });
        }
    });
});

1 个答案:

答案 0 :(得分:0)

您希望将onchange事件用于单选按钮而不是onclick按钮。

所以我会在你的代码中建议这样的事情:

$tip.find('.close').bind('change', function () {
  popover.hide();
});