Javascript 在表格内的文本框中输入数据时选中复选框
我想知道,当数据输入到表中的文本框中时,是否可以Javascript 在表格内的文本框中输入数据时选中复选框,javascript,jquery,Javascript,Jquery,我想知道,当数据输入到表中的文本框中时,是否可以“Checked=true”选中行的复选框 下面是执行此操作的代码jquery代码,但它正在选中所有复选框。我将感谢任何帮助 jquery代码: <script> jQuery('[id$="enteredValue"]').change(function() { jQuery('[id$="check"]').attr('checked', true); }); </script> j
“Checked=true”
选中行的复选框
下面是执行此操作的代码jquery代码,但它正在选中所有复选框。我将感谢任何帮助
jquery代码:
<script>
jQuery('[id$="enteredValue"]').change(function() {
jQuery('[id$="check"]').attr('checked', true);
});
</script>
jQuery('[id$=“enteredValue”]')。更改(函数(){
jQuery('[id$=“check”]')。attr('checked',true);
});
html代码
<table id="table-2">
<thead>
<tr>
<th>Select</th>
<th>Enter Qty</th>
<th> Suggested Units</th>
<th> Cost</th>
<th>Brand</th>
</tr>
<thead>
<tbody>
<tr>
<td><apex:inputCheckbox id="check" value="{!objectRow.selected}"/> </td>
<td><apex:inputText id="enteredValue" value=" {!objectRow.EnteredValue}" /></td>
<td><apex:outputText value="{!objectRow.Reorder_Amount}"/></td>
<td><apex:outputText value="{!objectRow.Reorder_Cost}" /></td>
<td><apex:outputText value="{!objectRow.Brand}" /></td>
</tr>
</tbody>
</table>
挑选
输入数量
建议单位
成本
烙印
这是因为您选择了所有复选框。仅选择文本输入行中的一个:
$(this).closest('tr').find('[id$="check"]').prop('checked', true);
如果将布尔值作为值传递,请改用prop
。有关详细信息,请参阅。试试这个
<script>
jQuery('[id$="enteredValue"]').change(function() {
$(this).closest('tr').find('[id$="check"]').prop('checked', true);
if(this.val()=="")
{
$(this).closest('tr').find('[id$="check"]').prop('checked', false);
}
});
</script>
jQuery('[id$=“enteredValue”]')。更改(函数(){
$(this).closest('tr').find('id$=“check”]').prop('checked',true);
如果(this.val()==“”)
{
$(this).closest('tr').find('id$=“check”]').prop('checked',false);
}
});
Jameen,谢谢您的帮助,但我使用了“tr”而不是“td”,这很有效。如果用户删除了texfield中的内容,我如何创建一个未选中复选框的函数。有什么想法吗?Jameem,非常感谢你我真的很感激。顺致敬意,