我想知道在表格内的文本框中输入数据时是否可以'Checked=true'
行的复选框。
这是执行此操作的代码jquery代码,但正在检查所有复选框。我将不胜感激。
jquery代码:
<script>
jQuery('[id$="enteredValue"]').change(function() {
jQuery('[id$="check"]').attr('checked', true);
});
</script>
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>
答案 0 :(得分:1)
那是因为 选择了所有复选框。只选择文本输入行中的那个:
$(this).closest('tr').find('[id$="check"]').prop('checked', true);
如果将布尔值作为值传递,请改用prop
。有关详细信息,请参阅https://api.jquery.com/attr/。
答案 1 :(得分:1)
试试这个..
<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>