【问题标题】:make radio button checked on click other idv在单击其他 idv 时选中单选按钮
【发布时间】:2014-01-02 02:36:30
【问题描述】:

嗨,我正在尝试制作一个我需要制作的函数

选中单选按钮

根据按钮属性值

应该等于单选按钮的值。

下面是我的代码

<table id="oustandingItems">
  <tr><th>Category</th></tr>
  <tr><td><input type="radio" name="mytest" value='124' /></td></tr>
  <tr><td><input type="radio" name="mytest" value="123"/></td></tr>
</table>


<button title ="124" class="findRow">Find Row</button>
<button title ="123" class="findRow">Find Row</button>



$(".findRow").click(function() { 
    var rad = $(this).attr('title');

    //alert($(this).attr('title'));
  var myValue = $('#oustandingItems').find('input[value=rad]').val()
   alert(myValue);

      //$("#myRow").val(myValue);
});

我需要检查单选按钮谁的值将等于按钮标题值

<button title ="124" class="findRow">Find Row</button>
<button title ="123" class="findRow">Find Row</button>

但这不起作用,请建议我如何实现这一目标

谢谢

【问题讨论】:

    标签: jquery attributes click radio


    【解决方案1】:

    您需要使用字符串连接来使用变量值rad,否则它会搜索值为rad 的输入元素,而不是查找存储在变量rad 中的值

    $('#oustandingItems').find('input[value=' + rad + ']').prop('checked', true)
    
    var myValue = $('#oustandingItems').find('input[value=' + rad + ']').val()
    

    演示:Fiddle

    【讨论】:

    • 嗨,你能帮我看看 $(this).css("border","1px solid black");我添加了这个以使单击元素突出显示它可以工作,但是当我单击其他也突出显示的元素时,我需要一次突出显示一个元素
    猜你喜欢
    • 1970-01-01
    • 2020-04-05
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2014-01-06
    • 2012-06-02
    相关资源
    最近更新 更多