Javascript 我有多个<;td>;使用复选框及其值。我想更改<;td>;
下面是我的HTML代码,它包含多个复选框,在Javascript 我有多个<;td>;使用复选框及其值。我想更改<;td>;,javascript,jquery,html,Javascript,Jquery,Html,下面是我的HTML代码,它包含多个复选框,在中分别有相应的值。我通过php获得点击复选框的值,php是一种数组格式$res[]。我想使我得到值的复选框消失,并使背景色变为红色,复选框的值可见。我在php中得到的复选框值为$res[0][seat]=>4和$res[1][seat]=>1其中4和1是值。如何使用jQuery实现这一点 <table> <tr> <td> <input name="chk" cl
中分别有相应的值。我通过php获得点击复选框的值,php是一种数组格式$res[]
。我想使我得到值的复选框消失,并使背景色变为红色,复选框的值可见。我在php中得到的复选框值为$res[0][seat]=>4
和$res[1][seat]=>1
其中4和1是值。如何使用jQuery实现这一点
<table>
<tr>
<td>
<input name="chk" class='chk' type="checkbox" value="1"/>
<label>1</label>
</td>
</tr>
<tr>
<td >
<input name="chk" class='chk' type="checkbox" value="2"/>
<label>2</label>
</td>
</tr>
<tr>
<td >
<input name="chk" class='chk' type="checkbox" value="3"/>
<label>3</label>
</td>
</tr>
<tr>
<td >
<input name="chk" class='chk' type="checkbox" value="4"/>
<label>4</label>
</td>
</tr>
</table>
1.
2.
3.
4.
试试这个:
$('.chk').on('click', function(e){
e.preventDefault();
if($(this).is(':checked')) {
$(this).hide();
$(this).closest('td').css('background-color','red');
}
});
已更新请尝试以下操作:
var arr=[4,1];//从php接收的数组列表
对于(i=0;i
1.
2.
3.
4.
在jquery中使用
var arrayValue = [4, 1];
$(".chk").filter(function () {
return arrayValue.indexOf(+this.value) != -1 // check arrayvalue is present in check box or not using indexOf
}).closest("td").css('background-color', 'red').find(".chk").hide(); // set background for closest td and hide chk
如何获取javascript中动态的php数组array@curious2lrn如果您期望页面加载,那么使用var arr=;但是对于这一点,您的页面应该是.php或.html,而不是.js。我正在运行一个while循环($row=mysql\u fetch\u assoc($result)){$res[]=$row;}我已经将它存储在$res[]中,这样我就可以在while循环之外使用它,那么如何将$res[0][seat](多个值)存储在javascript数组@同一页面上,以及.php扩展名为什么要在$res[0][seat]中使用key seat。如果您可以使用$res[0]=4,$res[1]=1,那么请执行以下操作:在document.ready部分var arr=;我正在运行一个while循环($row=mysql\u fetch\u assoc($result)){$res[]=$row;}我将它存储在$res[]中,这样我就可以在while循环之外使用它了,那么如何将$res[0][seat](多个值)存储在javascript数组中呢