Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
单选按钮包括Jquery_Jquery_Html_Radio Button - Fatal编程技术网

单选按钮包括Jquery

单选按钮包括Jquery,jquery,html,radio-button,Jquery,Html,Radio Button,编辑**Bouchaala Sabri答案非常有效 我试图将一些jquery包含到我的页面中时遇到问题。由于某种原因,它不起作用。不确定脚本是否错误,或者jquery是否正确拉入 它基本上是一个脚本,允许用户从前三个单选按钮中选择一个选项,从第二批三个按钮中选择一个选项,但是如果选中了底部三个按钮中的任何一个,那么如果之前选中了前六个按钮,则将取消选中它们 <script type="text/javascript" src="https://ajax.googleapis.com/aja

编辑**Bouchaala Sabri答案非常有效

我试图将一些jquery包含到我的页面中时遇到问题。由于某种原因,它不起作用。不确定脚本是否错误,或者jquery是否正确拉入

它基本上是一个脚本,允许用户从前三个单选按钮中选择一个选项,从第二批三个按钮中选择一个选项,但是如果选中了底部三个按钮中的任何一个,那么如果之前选中了前六个按钮,则将取消选中它们

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
  $yearstages = $('input[name="keystage1yr2"],input[name="keystage1yr1"]');
    $savestages = $('input[name="keystage1save"]');
    $('#radios').on('change', 'input', function() {
        if (this.name == "keystage1save") {
            $yearstages.filter('input:checked').prop('checked', false);
        } else {
            $savestages.filter('input:checked').prop('checked', false);
        }
    });
</script>
</head>

<body>



<div id="radios">
<p>
<input class="radio" type="radio" name="keystage1yr1" value="Paper" /> <span>&#163;25</span>
<input class="radio" type="radio" name="keystage1yr1" value="CD" /> <span>&#163;25 excl VAT</span>
<input class="radio" type="radio" name="keystage1yr1" value="Paper & CD" /> <span>&#163;40 excl VAT</span>
</p>
<p>
<input class="radio" type="radio" name="keystage1yr2" value="Paper" /> <span>&#163;25</span>
<input class="radio" type="radio" name="keystage1yr2" value="CD" /> <span>&#163;25 excl VAT</span>
<input class="radio" type="radio" name="keystage1yr2" value="Paper & CD" /> <span>&#163;40 excl VAT</span>
</p>
<p>
<input class="radio" type="radio" name="keystage1save" value="Paper" /> <span>&#163;47.50</span>
<input class="radio" type="radio" name="keystage1save" value="CD" /> <span>&#163;47.50 excl VAT</span>
<input class="radio" type="radio" name="keystage1save" value="Paper & CD" /> <span>&#163;75 excl VAT</span>
</p>
</div>

$yearstages=$('input[name=“keystage1yr2”],input[name=“keystage1yr1”]);
$savestages=$('input[name=“keystage1save”]”);
$('#radios')。打开('change','input',function(){
如果(this.name==“keystage1save”){
$yearstages.filter('input:checked').prop('checked',false);
}否则{
$savestages.filter('input:checked').prop('checked',false);
}
});

£25
£25不包括增值税
£40不包括增值税

£25 £25不包括增值税 £40不包括增值税

£47.50 £47.50不包括增值税 £75不含增值税


您必须将以下内容

$('#radios').on('change', 'input', function() {
    if (this.name == "keystage1save") {
        $yearstages.filter('input:checked').prop('checked', false);
    } else {
        $savestages.filter('input:checked').prop('checked', false);
    }
});

进入
$(函数(){…})
。放置代码而不是点。此代码在加载页面后执行。

您必须放置以下内容

$('#radios').on('change', 'input', function() {
    if (this.name == "keystage1save") {
        $yearstages.filter('input:checked').prop('checked', false);
    } else {
        $savestages.filter('input:checked').prop('checked', false);
    }
});

进入
$(函数(){…})
。放置代码而不是点。此代码在加载页面后执行。

永远不要忘记将代码包装在

jQuery(document).ready(function($){

})

永远不要忘记将代码包装在

jQuery(document).ready(function($){

})

在加载DOM之前执行脚本。请确保按如下方式包装代码:

$(function(){
  $yearstages = $('input[name="keystage1yr2"],input[name="keystage1yr1"]');
    $savestages = $('input[name="keystage1save"]');
    $('#radios').on('change', 'input', function() {
        if (this.name == "keystage1save") {
            $yearstages.filter('input:checked').prop('checked', false);
        } else {
            $savestages.filter('input:checked').prop('checked', false);
        }
    });
});

这将在加载DOM之后执行代码。

在加载DOM之前执行脚本。请确保按如下方式包装代码:

$(function(){
  $yearstages = $('input[name="keystage1yr2"],input[name="keystage1yr1"]');
    $savestages = $('input[name="keystage1save"]');
    $('#radios').on('change', 'input', function() {
        if (this.name == "keystage1save") {
            $yearstages.filter('input:checked').prop('checked', false);
        } else {
            $savestages.filter('input:checked').prop('checked', false);
        }
    });
});
这将在加载DOM后执行代码