Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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_Variables_Button_Onclick_Radio - Fatal编程技术网

Jquery 单击单选按钮时,一个变量将更改为另一个变量

Jquery 单击单选按钮时,一个变量将更改为另一个变量,jquery,variables,button,onclick,radio,Jquery,Variables,Button,Onclick,Radio,我有一个简单的2选项单选按钮。我认为我的代码可以工作,并尝试了许多其他版本,但我只是错过了一些东西。当单选按钮更改时,我需要更改var类型的卡片。该变量用于后面的等式中 选中的输入值155应将卡片类型更改为相等的BoxCard和 选中的输入值145应将卡的类型更改为相同的单卡 <input name="SELECT___CD-0035___33" value="155" onclick="change_option('SELECT___CD-0035___33',this.value)"

我有一个简单的2选项单选按钮。我认为我的代码可以工作,并尝试了许多其他版本,但我只是错过了一些东西。当单选按钮更改时,我需要更改var类型的卡片。该变量用于后面的等式中

选中的输入值155应将卡片类型更改为相等的BoxCard和 选中的输入值145应将卡的类型更改为相同的单卡

<input name="SELECT___CD-0035___33" value="155" onclick="change_option('SELECT___CD-0035___33',this.value)" type="radio">Box Cards (Sold in Multiples of 3) <br>
<input checked="checked" name="SELECT___CD-0035___33" value="154" onclick="change_option('SELECT___CD-0035___33',this.value)" type="radio"> Single Cards (Sold in sets of 12 Cards/12 Envelopes)<br>

var singleCards = 12
var boxCards = 3
var typeOfCards = singleCards
$("input[value='155']").click(function() {
    typeOfCards = boxCards;
});
$("input[value='154']").click(function() {
    typeOfCards = singleCards;
});
Box卡(以3的倍数出售)
单张卡片(以12张卡片/12个信封为一套出售)
var单卡=12 var boxCards=3 var TYPEOFCARD=单卡 $(“输入[value='155']”)。单击(函数(){ 卡片类型=盒式卡片; }); $(“输入[value='154']”)。单击(函数(){ 卡的类型=单卡; });
处理程序可能没有连接,因为它们不在document.ready中,并且脚本在创建元素之前正在运行

尝试:

顺便说一句,如果您有jQuery单击处理程序,您可能也不需要onclick


检查它,它在这个小提琴中工作:

不确定为什么为单选按钮指定了“onclick”

试试这个:

   <script>
    $(document).ready(function () {
        var singleCards = 12
        var boxCards = 3
        var typeOfCards = singleCards
        $(".radioSelect").click(function () {
            if ($(this).val() == "155")
                typeOfCards = boxCards;
            else
                typeOfCards = singleCards;
            alert(typeOfCards);
        });
    });
   </script>

<input name="SELECT___CD-0035___33" value="155" class="radioSelect" type="radio" />Box Cards (Sold in Multiples of 3) <br/>
<input checked="checked" name="SELECT___CD-0035___33" value="154" class="radioSelect" type="radio" /> Single Cards (Sold in sets of 12 Cards/12 Envelopes)<br/>

$(文档).ready(函数(){
var单卡=12
var boxCards=3
var TYPEOFCARD=单卡
$(“.radioSelect”)。单击(函数(){
如果($(this.val()=“155”)
卡片类型=盒式卡片;
其他的
卡的类型=单卡;
警报(卡片类型);
});
});
盒式卡片(以3的倍数出售)
单张卡(一套12张卡/12个信封出售)
   <script>
    $(document).ready(function () {
        var singleCards = 12
        var boxCards = 3
        var typeOfCards = singleCards
        $(".radioSelect").click(function () {
            if ($(this).val() == "155")
                typeOfCards = boxCards;
            else
                typeOfCards = singleCards;
            alert(typeOfCards);
        });
    });
   </script>

<input name="SELECT___CD-0035___33" value="155" class="radioSelect" type="radio" />Box Cards (Sold in Multiples of 3) <br/>
<input checked="checked" name="SELECT___CD-0035___33" value="154" class="radioSelect" type="radio" /> Single Cards (Sold in sets of 12 Cards/12 Envelopes)<br/>