使用jQ-ui的按钮功能
<script>
$(function() {
$( "#radio" ).buttonset();
});
</script>
<div id="radio">
<input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
</div>
有没有办法一次取消选中buttonset的所有单选按钮?
答案 0 :(得分:32)
您可以使用以下内容取消选中它们(针对jQuery UI 1.9进行了更新:
$('#radio input').removeAttr('checked');
// Refresh the jQuery UI buttonset.
$( "#radio" ).buttonset('refresh');
工作JSFiddle。
答案 1 :(得分:15)
您可以匹配所有单选按钮,并使用prop()取消选中它们。
但是,您还必须在执行此操作后刷新buttonset小部件:
$("#radio").find("input:radio").prop("checked", false).end()
.buttonset("refresh");
答案 2 :(得分:14)
在jQuery 1.6版本之前
$(':radio').attr('checked', false);
OR
$(':radio').removeAttr('checked');
jQuery 1.6 +
之后$(':radio').prop('checked', false);
OR
$(':radio').removeProp('checked');
答案 3 :(得分:1)
偶然发现了这个...使用jQuery 1.9.1使用按钮组的类名,所有按钮最初都未设置。尚不确定是否会对此产生影响,但不方便知道。
$( "div.myclass" ).buttonset();
<div id="myDiv" class="myclass">
<input type="radio" name="myname" id="id1" value="1"><label for="id1">Label1</label>
<input type="radio" name="myname" id="id2" value="2"><label for="id2">Label2</label>
<input type="radio" name="myname" id="id3" value="3"><label for="id3">Label2</label>
</div>
答案 4 :(得分:1)
Javascirpt实现此目标的本机方法
function reset(){
//var list = document.querySelectorAll('input[type=radio]');
var list =document.querySelectorAll('input[type="radio"]:checked')
debugger
list.forEach(element => {
if(element.checked){element.checked=false}}
);
}
<div id="myDiv" class="myclass">
<input type="radio" name="myname" id="id1" value="1"><label for="id1">Label1</label>
<input type="radio" name="myname" id="id2" value="2"><label for="id2">Label2</label>
<input type="radio" name="myname" id="id3" checked value="3"><label for="id3">Label3</label>
</div>
<button onclick="reset()">reset me</button>
答案 5 :(得分:0)
这对我有用
$('input:radio[name="RadioName"]').each(function () { $(this).attr('checked', false); });
答案 6 :(得分:0)
对于JQuery 1.12+
在DECLARE
type sh_id is varray(10) of tab.col1%type;
a_cnts number;
b_cnts number;
lv varchar2(20) := NULL; -- This is never modified in your code.
ids sh_id := sh_id(1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
BEGIN
FOR i IN 1 .. ids.COUNT LOOP
SELECT count(b.sub_id)
INTO b_cnts
FROM tab a
INNER JOIN tab1 b
ON ( <some join conditions> ) -- you need to specify the join
WHERE a.id = ids(i);
INSERT INTO new_tab
SELECT DISTINCT
ids(i),
b.sub_id,
lv
FROM tab a
INNER JOIN tab1 b
ON ( <some join conditions> ) -- you need to specify the join
WHERE a.id = ids(i);
-- Assuming you have a trigger to populate tab or tab1 from new_tab then
a_cnts := b_cnts + SQL%ROWCOUNT;
-- Otherwise:
SELECT count(b.sub_id)
INTO a_cnts
FROM tab a
INNER JOIN tab1 b
ON ( <some join conditions> ) -- you need to specify the join
WHERE a.id = ids(i);
DBMS_OUTPUT.PUT_LINE( ids(i) || CHR(9) || b_cnts || CHR(9) || a_cnts );
END LOOP;
-- Commit outside the loop
COMMIT;
END;
/
内包装单选按钮并为其指定一个ID(例如“ radio”)
DT: array[0..3] of TVarType = (varString, varInteger, varDouble, varBoolean);