JavaScript检查复选框时,输入框被勾选 - 复选框数组[]
我有一个简单的JavaScript问题。我有一个复选框和一个输入框。JavaScript检查复选框时,输入框被勾选 - 复选框数组[]
当用户输入文本到输入框(onkeydown)我希望它检查行中的相应复选框。
我的复选框全部共享数组checkbox[]
。
我的简化语法是:
<table>
<?php if(isset($records)) : foreach ($records as $row) : ?>
<tr>
<td>
<input type=checkbox name="editcustomer[]" id="editcustomer[]" value="<?php echo $row->id ?>">
</td>
<td>
<input type="text" name="customer_name_<?php echo $row->id ?>" id="customer_name_<?php echo $row->id ?>" value="<?php echo $row->customer_name ; ?>" onclick="document.getElementById('editcustomer<?php echo $row->id ?>').checked = true;">
</td>
<tr>
<?php endforeach ; ?>
</table>
作为复选框的名称不是唯一的,只有它的价值我怎么告诉JavaScript来检查哪些复选框?
<input type="text" name="customer_name_<?php echo $row->id ?>" id="customer_name_<?php echo $row->id ?>" value="<?php echo $row->customer_name ; ?>" onclick="document.getElementById('editcustomer<?php echo $row->id ?>').checked = true;">
帮助一如既往的赞赏。
感谢
HTML
<input type="checkbox" name="checkbox[]"/>
<input type="text" name="name1" id="name1" />
<br>
<input type="checkbox" name="checkbox[]"/>
<input type="text" name="name2" id="name2" />
<br>
<input type="checkbox" name="checkbox[]" />
<input type="text" name="name3" id="name3" />
jQuery的
$(':text').change(function(){
$(this).prev(':checkbox').attr('checked','true');
});
希望这有助于。 此致敬礼。
Hi X因子。谢谢你的时间。不像每个小提琴一样工作,http://jsfiddle.net/A4GaF/1/。任何想法为什么?脚本如何知道它必须找到哪个复选框。所以在小提琴上,如果我输入任何框,它应该检查相应的复选框。谢谢 – Smudger 2013-03-04 11:14:17
好吧,让我有一个loook – 2013-03-04 11:30:26
我更新了你的代码,但你必须添加jQuery为该@Smudger – 2013-03-04 11:50:49
通话的onkeydown /平变化与通过这个作为一个参数,然后在功能使用 '功能ABC(ELEM) {$ (本).parent()的next()找到('的方法:。复选框').attr(' 检查”,假); }' – 2013-03-04 10:49:34
你可以通过看小提琴来协助吗? http://jsfiddle.net/A4GaF/1/ – Smudger 2013-03-04 11:14:32