Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 想要从popover中的单选按钮获取结果吗_Javascript_Jquery_Twitter Bootstrap - Fatal编程技术网

Javascript 想要从popover中的单选按钮获取结果吗

Javascript 想要从popover中的单选按钮获取结果吗,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我的代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!

我的代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <h2>Hello</h2>
    <button type="button" id="example" class="btn btn-danger" data-container="body" data-html="true" data-toggle="popover" data-placement="right" data-content="&lt;form id='myform' class='form-horizontal'&gt;
&lt;input type='radio' id='rb1' name='keys' value='Adult' bind-value='key'&gt;
Adult  &lt;br&gt;
&lt;input type='radio' id='rb2' name='keys' value='Child' bind-value='key'&gt;
Child  &lt;br&gt;
&lt;input type='radio' id='rb3' name='keys' value='Concession' bind-value='key'&gt;
Concession  &lt;/form&gt;" data-original-title="Select seat type">Hello
    </button>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#example').popover();
        $('#myform input').on('change', function() {
            alert($('input[name=keys]:checked').val());
        });
    });
    </script>
</body>

</html>

引导101模板
你好
你好
$(文档).ready(函数(){
$(“#示例”).popover();
$('#myform input')。在('change',function()上{
警报($('input[name=keys]:选中').val();
});
});
我想在警报中显示所选单选按钮(放置在popover中)的值。这段代码根本不会发出警报。popover显示完美,单选按钮也显示正确。在弹出窗口中选择单选按钮时,只有警报不会显示。请帮忙

类似这样的东西

$("input:radio[name=keys]").click(function() {
    var value = $(this).val();
    alert(value);
});
这里有类似的答案; 类似这样的东西

$("input:radio[name=keys]").click(function() {
    var value = $(this).val();
    alert(value);
});
这里有类似的答案;
问题在于何时初始化侦听器。在弹出窗口显示之前,表单不存在。因此,您需要在之后初始化事件侦听器

以下是片段:

$(文档).ready(函数(){
$(“#示例”).popover();
$('#示例').on('show.bs.popover',function(){
$('#myform input')。在('click',function()上{
警报($('input[name=keys]:选中').val();
});
});
});

引导101模板
你好
你好

问题在于何时初始化侦听器。在弹出窗口显示之前,表单不存在。因此,您需要在之后初始化事件侦听器

以下是片段:

$(文档).ready(函数(){
$(“#示例”).popover();
$('#示例').on('show.bs.popover',function(){
$('#myform input')。在('click',function()上{
警报($('input[name=keys]:选中').val();
});
});
});

引导101模板
你好
你好
$(文档).ready(函数(){
$(“#示例”).popover();
$(“form”).find('input[type=“radio”]”)。on('change',function(){
警报($('input[name=keys]:选中').val();
});
});
$(文档).ready(函数(){
$(“#示例”).popover();
$(“form”).find('input[type=“radio”]”)。on('change',function(){
警报($('input[name=keys]:选中').val();
});
});