简体   繁体   English

具有相同名称的先前选择的单选按钮的呼叫功能

[英]Call function on previously selected radio button with the same name

Hello I have some radio buttons with different radio groups name. 您好,我有一些具有不同无线电组名称的单选按钮。 I want to call the function on the previously selected radio button for that specific group. 我想在该特定组的先前选择的单选按钮上调用该函数。

If I check the radio button then select the different radio button from the same group. 如果我选中单选按钮,则从同一组中选择其他单选按钮。 I want call the function or add class on the previously selected radio button of the same group in jQuery. 我想在jQuery中同一组的先前选择的单选按钮上调用函数或添加类。

Here is the example code - 这是示例代码-

RadioGroup1Button 1: <input type='radio' name='radioGroup1' /><br />
RadioGroup1Button 2: <input type='radio' name='radioGroup1' /><br />
RadioGroup2Button 1: <input type='radio' name='radioGroup2' /><br />
RadioGroup2Button 2: <input type='radio' name='radioGroup2' /><br />
RadioGroup2Button 3: <input type='radio' name='radioGroup2' /><br />

Please help 请帮忙

Is it something like this you want? 你想要这样的东西吗?

$("input:radio").on("mousedown", function() {
  var name = $(this).attr("name");
  if ($("input:radio[name='" + name + "']:checked").length == 1 && $(this).is(":not(:checked)")) {
    $("input:radio[name='" + name + "']").removeClass("PrevChecked");
    $("input:radio[name='" + name + "']:checked").addClass("PrevChecked");
  }
});

Demo 演示

 $("input:radio").on("mousedown", function() { var name = $(this).attr("name"); if ($("input:radio[name='" + name + "']:checked").length == 1 && $(this).is(":not(:checked)")) { $("input:radio[name='" + name + "']").removeClass("PrevChecked"); $("input:radio[name='" + name + "']:checked").addClass("PrevChecked"); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> RadioGroup1Button 1: <input type='radio' name='radioGroup1' /><br /> RadioGroup1Button 2: <input type='radio' name='radioGroup1' /><br /> RadioGroup2Button 1: <input type='radio' name='radioGroup2' /><br /> RadioGroup2Button 2: <input type='radio' name='radioGroup2' /><br /> RadioGroup2Button 3: <input type='radio' name='radioGroup2' /><br /> 

暂无
暂无

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

相关问题 如何根据所选的单选按钮调用功能 - How to call a function depending on the radio button selected 如何从先前选择的单选按钮中删除属性? - How to remove radio button checked attribute from previously selected? 当有多个具有相同名称的单选按钮时,如何检查选择了哪个单选按钮? (使用jquery) - How do I check which radio button is selected when there are multiple radio buttons with the same name? (using jquery) 如何使用 javascript 获取多个单选按钮具有相同名称的选定单选按钮的值 - How to get the value of selected radio button where multiple radio buttons have same name using javascript 从下拉列表中单击相同选项时调用/触发功能 - Call / fire function when click on same option from dropdown list which was previously selected 在 jQuery 中的 function 中选中选中的单选按钮 - Get selected radio button on selected in function in jQuery 为选定的单选按钮div添加类别名称 - Add class name for selected radio button div 如果选择了相同的单选按钮值,则发出警报 - Alert if same value of radio button is selected 如果id和name相同,如何启用/禁用一个单选按钮(如果选择了另一个按钮) - how to enable / disable one radio button if another is selected when id and name are same 在 angular7 中单击时将一起选择具有相同表单控件名称的单选按钮 - radio button with same formcontrol name is getting selected together on click in angular7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM