如何根据数据代码值单击单选按钮?
<input name="shipping_method" type="radio" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping" class="radio" data-code="Free">
<input name="shipping_method" type="radio" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping" class="radio" data-code="Sale">发布于 2015-09-23 17:04:46
这应该会起到作用:)
$('input:radio[data-code="Sale"]').click();<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<input name="shipping_method" type="radio" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping" class="radio" data-code="Free">
<input name="shipping_method" type="radio" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping" class="radio" data-code="Sale">
发布于 2015-09-23 17:06:02
您可以使用input的属性来执行此操作。
例如,参见下面的代码。
$(document).ready(function(){
$("input[data-code = 'Free']").click(function(){
alert("hi");
});
});DEMO
发布于 2015-09-23 17:06:00
$("input[data-code='Sale']").click(function(){alert('clicked');});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="shipping_method" type="radio" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping" class="radio" data-code="Free">
<input name="shipping_method" type="radio" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping" class="radio" data-code="Sale">
https://stackoverflow.com/questions/32735203
复制相似问题