您好,登錄后才能下訂單哦!
因為PHP接收要用 數(shù)組形式的 復選框,正常情況下 JQ可如果是這種
直接使用 $("input[name=ptpt])即可。但是這種php接收的只是最后一個值,字符串。
<label><input type='checkbox' name='ptpt' value='a1' />a1</label>
<label><input type='checkbox' name='ptpt' value='a3' />a3</label>
<label><input type='checkbox' name='ptpt' value='a6' />a6</label>
<label><input type='checkbox' name='ptpt' value='a9' />a9</label>
這樣PHP接收的是一個 ptpt的數(shù)組
<form method="post" id="form1" name="form1" action="" >
<label><input type='checkbox' name='ptpt[1]' value='a1' />a1</label>
<label><input type='checkbox' name='ptpt[3]' value='a3' />a3</label>
<label><input type='checkbox' name='ptpt[6]' value='a6' />a6</label>
<label><input type='checkbox' name='ptpt[9]' value='a9' />a9</label>
<input type="button" value="全選" onclick="">
<input type="button" value="反選" onclick="">
<input type="button" value="取消全選" onclick="">
<script src="jquery-1.7.2.min.js"></script>
<script>
$(function(){
var chks = $(':checkbox[name^="ptpt["]'); //匹配name開頭為 ptpt[ 的部分
$(':button:eq(0)').click(function(){
chks.attr('checked','checked');
})
$(':button:eq(1)').click(function(){
chks.each(function(){
if($(this).attr('checked')=='checked')
$(this).removeAttr('checked');
else
$(this).attr('checked','checked');
});
})
$(':button:eq(2)').click(function(){
chks.removeAttr('checked');
})
})
</script>
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。