Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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/9/solr/3.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_Label_Radio - Fatal编程技术网

Jquery 根据单选值更改链接按钮名称

Jquery 根据单选值更改链接按钮名称,jquery,label,radio,Jquery,Label,Radio,我有一个带有可选择的输入单选按钮的表格。2个单选输入按钮的值为“P2”或“P1”,其余值以S开头,如下所示 <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="P2"/> <input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(tr

我有一个带有可选择的输入单选按钮的表格。2个单选输入按钮的值为“P2”或“P1”,其余值以S开头,如下所示

<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="P2"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="P1"/>


<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S111"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S112"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S131"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S132"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S121"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S122"/>
<a href='javascript: submitform("subsOptionform")' tabindex="14" class="right button blue">Subscribe</a>

我想有一个链接的标签从订阅更改为购买信用卡时,2个单选按钮被选中

谢谢你的帮助


谢谢

首先,您需要将
输入
的ID更改为唯一值,否则无法保证任何操作正常

接下来,尝试将其放入
$(文档).ready(函数(){


你有8个ID完全相同的元素。祝你一切顺利。而且,你的代码中没有一点jQuery。我会对jQuery的功能做一些研究,然后尝试重构你的代码以使用它。lol@Blender它们看起来确实像90年代初的代码。谢谢你的回答。基本上上面引用的代码就是这样在浏览器上查看时复制了urce代码。所讨论的页面是用java开发的,初始标记使用html5和jQuery。事实上,我们表格上8个单选按钮的显示是通过jQuery实现的,以根据单选显示不同的价格。我知道有一个特定的id没有帮助。需要重新考虑原因。如果他在该页面上有多个
$('.blue')
实例,您的脚本将无法按预期工作。@mblase75 True,但他没有给我多少工作空间(即,ID将是最佳的)大家好,谢谢你们的回复。我可以问一下为什么使用.blue吗?我们可以创建其他类吗?a链接html会是什么样子吗?@george我使用了
blue
,因为你这样做了。你给链接的类不一定决定链接的外观,除非你在样式表中指定它。例如,你可以给链接
class='class5]橙色“
,它的颜色仍然是蓝色。
$('.radio').change(function(){
    if($(this).attr('value') === 'P1' || $(this).attr('value') === 'P2'){
        $('.blue').text('Buy credits');
    }else{
        $('.blue').text('Subscribe');
    }
});