【发布时间】:2022-01-23 22:45:26
【问题描述】:
我正在编写一个代码,我想通过 Jquery 检查单选按钮,有一些链接,当我单击特定链接时,它会检查单选按钮,单选按钮的 Id 被传递给 jquery click 函数,我得到该 id 并将其存储在变量中,如何通过 var id 访问该单选按钮元素!!!!
//Html
<ul class="footer-links">
<li>Services</li>
<li><a href="#scrollup-content" data-id="tab-1">Brand Management</a></li>
<li><a href="#scrollup-content" data-id="tab-2">In & Outdoor Signage</a></label></li>
</ul>
//jquery
$(".footer-links li a").on("click",function(){
var id = $(this).data();
console.log(id)
$('#tab-2').attr('checked', true); // this is working properly
$('#id').attr('checked', true);// how to do? I want this to work
})
【问题讨论】:
标签: html jquery radio-button element var