简体   繁体   English

弹出点击单选按钮

[英]Popup a radio button on click

I have two radio buttons as following in a form 我有两个单选按钮,形式如下

<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

The problem I am having is although on selecting the radio button popup appears but i want to close it by on click NO radio button. 我遇到的问题是,虽然在选择单选按钮时出现了弹出窗口,但我想通过单击“否”单选按钮来关闭它。

Here is the JS 这是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;
                });
            });
        }
    });
});

You want to use the onchange event for radio buttons instead of the onclick one. 您想将onchange事件用于单选按钮,而不是onclick事件。

So I would suggest something like this in your code: 所以我会在您的代码中建议这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM