Javascript Can´;当取消选中单选按钮时,不能更改值

Javascript Can´;当取消选中单选按钮时,不能更改值,javascript,php,jquery,html,checkbox,Javascript,Php,Jquery,Html,Checkbox,我有这个输入,它是一个单选按钮(示例2),我有其他单选按钮,具有不同的用途 <input name="example2" id="sent" type="radio" value="3"> <input name="example2a" id="sent2a" type="radio" value=" ORDER BY date_hour DESC "> 我可以在选中单选按钮时更改状态,但在取消选中单选按钮时无法更改状态 我要寻找的是,如

我有这个输入,它是一个单选按钮(示例2),我有其他单选按钮,具有不同的用途

       <input name="example2" id="sent" type="radio" value="3">
       <input name="example2a" id="sent2a" type="radio" value=" ORDER BY date_hour DESC   ">
我可以在选中单选按钮时更改状态,但在取消选中单选按钮时无法更改状态

我要寻找的是,如果单选按钮被选中,我希望状态为3,如果单选按钮未选中,状态为2


谢谢您的帮助。

您可以使用
单击

而不是
更改

请尝试使用此代码段示例


$(文档).ready(函数(){
//不可勾选
(函数($){
$.fn.uncheckableRadio=函数(){
返回此值。每个(函数(){
$(this.mousedown(function()){
$(this.data('wasChecked',this.checked);
});
$(此)。单击(函数(){
if($(this).data('wasChecked'))
此项检查=错误;
});
});
};
})(jQuery);
$('input[type=radio]')。取消选中leradio();
//无线电点击
$(“#已发送,#sent2a”)。单击(函数(){
如果($(this).prop(“选中”)){
状态=3;
}否则{
状态=2;
}
$(“#status_span”).html(status)
});
})
A-
B-
地位-
试试看

只用

$('#sent').bind('click', function() {
  //if un-checked
  if(!$(this).is(':checked')) {
    status=2;
  } else {
    //if checked
    status=3;
  }
});

您的两个单选按钮都具有相同的
id=“send”
。那么它将如何工作呢?如果我更改id,结果是sameYes,这是因为您只有
$(“#sent”)的代码。更改
,而不是另一个。让我给你第二个输入的代码,我只想取消选中第一个输入,并更改“status=2”,我只是不能这样做,在这种情况下提供了下面的答案。使用
$(this).is(':checked')
结果是相同的错误,您必须选择以“sent”开头而不是以$结尾的收音机('input:radio[id^=“sent”]')。on('change',function(){'Your code here');我改变了我的起源,结果是相同的似乎是工作在这里。我通过交换状态号更新了答案。也许你现在可以查一下
$('#sent').change(function(){
    if( $('#sent').prop("checked")){
      status=3;
    } else {
      status=2;
}
$('input:radio[id^="sent"]').on('change', function(){'Your code here'});
$('#sent').bind('click', function() {
  //if un-checked
  if(!$(this).is(':checked')) {
    status=2;
  } else {
    //if checked
    status=3;
  }
});