如何动态设置html复选框选中与不选中? jquery checkbox怎么选中和不选中?
\u5982\u4f55\u4f7f\u7528javascript\u6765\u8bbe\u7f6echeckbox\u7684\u9009\u4e2d\u72b6\u6001\u4ee3\u7801\u5982\u4e0b\uff1avar obj = document.getElementById("tt");var value = obj.checked;alert(value);// \u82e5\u9009\u4e2d\uff0c\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalseobj.checked = false;// \u8bbe\u7f6e\u590d\u9009\u6846\u4e3a\u4e0d\u9009\u4e2d\u72b6\u6001
\u62d3\u5c55\u8d44\u6599\uff1aJavaScript\u4e00\u79cd\u76f4\u8bd1\u5f0f\u811a\u672c\u8bed\u8a00\uff0c\u662f\u4e00\u79cd\u52a8\u6001\u7c7b\u578b\u3001\u5f31\u7c7b\u578b\u3001\u57fa\u4e8e\u539f\u578b\u7684\u8bed\u8a00\uff0c\u5185\u7f6e\u652f\u6301\u7c7b\u578b\u3002\u5b83\u7684\u89e3\u91ca\u5668\u88ab\u79f0\u4e3aJavaScript\u5f15\u64ce\uff0c\u4e3a\u6d4f\u89c8\u5668\u7684\u4e00\u90e8\u5206\uff0c\u5e7f\u6cdb\u7528\u4e8e\u5ba2\u6237\u7aef\u7684\u811a\u672c\u8bed\u8a00\uff0c\u6700\u65e9\u662f\u5728HTML\uff08\u6807\u51c6\u901a\u7528\u6807\u8bb0\u8bed\u8a00\u4e0b\u7684\u4e00\u4e2a\u5e94\u7528\uff09\u7f51\u9875\u4e0a\u4f7f\u7528\uff0c\u7528\u6765\u7ed9HTML\u7f51\u9875\u589e\u52a0\u52a8\u6001\u529f\u80fd\u3002
$(function () {
// \u52a8\u6001\u7ed1\u5b9a\u9ed8\u8ba4\u72b6\u6001
// $("#ck").attr("checked",true)//\u9009\u4e2d
// $("#ck").attr("checked",false)//\u672a\u9009\u4e2d
//\u70b9\u51fb\u5224\u65ad\u9009\u4e2d\u8fd8\u662f\u672a\u9009\u4e2d
$("#ck").click(function () {
if ($(this).is(":checked")) {
alert("\u9009\u4e2d");
} else {
alert("\u672a\u9009\u4e2d");
}
})
});
jQuery\u662f\u4e00\u4e2a\u5feb\u901f\u3001\u7b80\u6d01\u7684JavaScript\u6846\u67b6\uff0c\u662f\u7ee7Prototype\u4e4b\u540e\u53c8\u4e00\u4e2a\u4f18\u79c0\u7684JavaScript\u4ee3\u7801\u5e93\uff08\u6216JavaScript\u6846\u67b6\uff09\u3002jQuery\u8bbe\u8ba1\u7684\u5b97\u65e8\u662f\u201cwrite Less\uff0cDo More\u201d\uff0c\u5373\u5021\u5bfc\u5199\u66f4\u5c11\u7684\u4ee3\u7801\uff0c\u505a\u66f4\u591a\u7684\u4e8b\u60c5\u3002\u5b83\u5c01\u88c5JavaScript\u5e38\u7528\u7684\u529f\u80fd\u4ee3\u7801\uff0c\u63d0\u4f9b\u4e00\u79cd\u7b80\u4fbf\u7684JavaScript\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u4f18\u5316HTML\u6587\u6863\u64cd\u4f5c\u3001\u4e8b\u4ef6\u5904\u7406\u3001\u52a8\u753b\u8bbe\u8ba1\u548cAjax\u4ea4\u4e92\u3002
jQuery\u7684\u6838\u5fc3\u7279\u6027\u53ef\u4ee5\u603b\u7ed3\u4e3a\uff1a\u5177\u6709\u72ec\u7279\u7684\u94fe\u5f0f\u8bed\u6cd5\u548c\u77ed\u5c0f\u6e05\u6670\u7684\u591a\u529f\u80fd\u63a5\u53e3\uff1b\u5177\u6709\u9ad8\u6548\u7075\u6d3b\u7684css\u9009\u62e9\u5668\uff0c\u5e76\u4e14\u53ef\u5bf9CSS\u9009\u62e9\u5668\u8fdb\u884c\u6269\u5c55\uff1b\u62e5\u6709\u4fbf\u6377\u7684\u63d2\u4ef6\u6269\u5c55\u673a\u5236\u548c\u4e30\u5bcc\u7684\u63d2\u4ef6\u3002jQuery\u517c\u5bb9\u5404\u79cd\u4e3b\u6d41\u6d4f\u89c8\u5668\uff0c\u5982IE 6.0+\u3001FF 1.5+\u3001Safari 2.0+\u3001Opera 9.0+\u7b49\u3002
2010\u5e741\u6708\uff0c\u4e5f\u662fjQuery\u7684\u56db\u5468\u5e74\u751f\u65e5\uff0cjQuery 1.4\u7248\u53d1\u5e03\uff0c\u4e3a\u4e86\u5e86\u795djQuery\u56db\u5468\u5c81\u751f\u65e5\uff0cjQuery\u56e2\u961f\u7279\u522b\u521b\u5efa\u4e86jquery14.com\u7ad9\u70b9\uff0c\u5e26\u6765\u4e86\u8fde\u7eed14\u5929\u7684\u65b0\u7248\u672c\u4e13\u9898\u4ecb\u7ecd\u3002
\u57281.3\u53ca\u66f4\u65e9\u7248\u672c\u4e2d\uff0cjQuery\u901a\u8fc7JavaScript\u7684eval\u65b9\u6cd5\u6765\u89e3\u6790json\u5bf9\u8c61\u3002\u57281.4\u4e2d\uff0c\u5982\u679c\u4f60\u7528\u7684\u6d4f\u89c8\u5668\u652f\u6301\uff0c\u5219\u4f1a\u4f7f\u7528\u539f\u751f\u7684JSON.parse\u89e3\u6790json\u5bf9\u8c61\uff0c\u8fd9\u6837\u5bf9json\u5bf9\u8c61\u7684\u4e66\u5199\u9a8c\u8bc1\u5219\u66f4\u4e3a\u4e25\u683c\u3002\u6bd4\u5982\uff1a{foo: "bar"}\u7684\u5199\u6cd5\u5c06\u4e0d\u4f1a\u88ab\u9a8c\u8bc1\u4e3a\u5408\u6cd5\u7684json\u5bf9\u8c61\uff0c\u5fc5\u987b\u5199\u6210{"foo":"bar"}\u3002\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u6253\u7b97\u5347\u7ea7\u52301.4\u7248\u672c\uff0c\u90a3\u4e48\u8fd9\u4e00\u70b9\u8981\u5c24\u5176\u6ce8\u610f\u3002
while($arr = mysql_fetch_array($res)) //取结果
{
switch($arr['值'])
{
case 1:
$checked = 'checked';
break;
case 0:
$checked = ''//只要checked,就是真,呵呵,你自己可以试验一下,老神奇了,如果设置成checked = 'false',依然是选中的
?>
<input type="checkbox" name="tmp" <?=$checked?> />
时间仓促,凑合着看吧
绛旓細杩欎釜鍦烘櫙瀹炵幇鐨勮瘽锛屼綘鐨勮嫃宸炶繖涓湴甯傜骇鍒殑id寰楁湁涓鍒欙紝骞朵笖瀹冨簳涓嬬殑鍖虹骇鍒簲璇ユ湁涓猵id锛岃繖涓猵id灞炴у氨鏄湴甯--鑻忓窞鐨勯偅涓猧d閲岄潰鐨勫硷紱灏卞儚Java妗嗘灦骞冲彴鐮斿彂 3784 37335
绛旓細<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <input type="checkbox" checked> <input type="checkbox"> <input type="checkbox"> <input type="checkbox"> <input type="checkbox"> <input type="checkbox"> <button id="btn" onclick="qx()">鍏ㄩ</...
绛旓細<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery-3.1.0.min.js"></script> <style> </style></head><body><input type="checkbox" checked><input type="checkbox"><input type="checkbox"><input type="c...
绛旓細<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>鏃犳爣棰樻枃妗</title><body> <table> <tr> <td><input type="checkbox" name="didian" id="k1"/>鍦扮偣</td> </tr> <tr> <td><input type="radio" name="place"/>鍖椾含<...
绛旓細3銆佸鐞澶嶉夋鐨勫硷細 鍦ㄦ彁浜よ〃鍗曟椂锛屽彲浠ヤ娇鐢↗avaScript澶勭悊澶嶉夋鐨勫硷紝骞跺皢鍏跺彂閫佸埌鏈嶅姟鍣ㄨ繘琛屽鐞嗐4銆佹搷浣滃閫夋鐨勭姸鎬侊細 鍙互浣跨敤JavaScript鍦ㄨ繍琛屾椂鏇存敼澶嶉夋鐨勭姸鎬侊紝渚嬪绂佺敤銆閫変腑鎴栧彇娑堥変腑銆傛讳箣锛屽墠绔閫夋锛坈heckbox锛夊彲浠ラ氳繃HTML鏍囩缁撳悎JavaScript鏉ュ疄鐜帮紝浣跨敤鎴峰彲浠ユ柟渚垮湴鍦ㄥ涓夐」涓繘琛...
绛旓細1銆侀鍏堟墦寮hbuilder杞欢锛屾柊寤哄嚑涓粯璁ょ殑澶嶉夋銆2銆佺劧鍚庡湪涓婃柟鐨剆tyle鏍囩璁剧疆input鐨勬牱寮忥紝鍏堣缃甶nput鐨刣isplay灞炴т负none锛屽皢榛樿鐨勫崟閫夋鍘绘帀锛屽湪璁剧疆涓涓嬪悇涓崟閫夋鐨刴argin鐨勮窛绂汇3銆佹帴鐫鍦ㄤ笅鏂圭户缁缃牱寮忥紝璁剧疆label鏍囩鐨刡efore鍜宎fter浼厓绱狅紝灏嗗師鏈塨efore鐨勫崟閫妗嗛変腑鐘舵佺殑灞炴р渃hecked+label...
绛旓細1234567891011121314151617181920212223242526272829303132333435<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>鏃犳爣棰樻枃妗</title><body> <table> <tr> <td><input type="checkbox" name="didian" id="k1"/>鍦扮偣</td> </tr> <tr> <t...
绛旓細<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script> <title> RunJS 婕旂ず浠g爜 </title> <script>...
绛旓細1銆乼ype:褰 type="radio" 鏃讹紝鎺т欢涓哄崟閫夋 褰 type="checkbox" 鏃讹紝鎺т欢涓澶嶉夋 2銆乿alue锛氭彁浜ゆ暟鎹埌鏈嶅姟鍣ㄧ殑鍊硷紙鍚庡彴绋嬪簭PHP浣跨敤锛3銆乶ame锛氫负鎺т欢鍛藉悕锛屼互澶囧悗鍙扮▼搴 ASP銆丳HP 浣跨敤 4銆乧hecked锛氬綋璁剧疆 checked="checked" 鏃讹紝璇ラ夐」琚粯璁閫変腑 娉ㄦ剰:鍚屼竴缁勭殑鍗曢夋寜閽紝name 鍙栧间竴瀹氳涓鑷...
绛旓細html 缂栫▼ 璁捐 鍐欎綔 鍦ㄨ繖涓ず渚嬩腑锛岀敤鎴峰彲浠ラ氳繃鐐瑰嚮姣忎釜澶嶉夋鏉閫夋嫨浠栦滑鎷ユ湁鐨勬妧鑳姐傜敱浜庡閫夋鍏佽澶氶」閫夋嫨锛屽洜姝ょ敤鎴峰彲浠ュ悓鏃堕夋嫨“缂栫▼”銆“璁捐”鍜“鍐欎綔”绛夊涓夐」銆傛荤粨锛氬閫夋鏄竴绉嶇伒娲讳笖鐢ㄦ埛鍙嬪ソ鐨勮〃鍗曞厓绱狅紝鐗瑰埆閫傜敤浜庨渶瑕佸湪涓缁勯潪浜掓枼閫夐」涓繘琛屽椤...