Javascript 选择器thjquery
我试图理解如何使用Jquery选择器 我有一个表,我想在模式中创建一个输入,我的困难实际上是如何正确使用选择器来访问Javascript 选择器thjquery,javascript,jquery,Javascript,Jquery,我试图理解如何使用Jquery选择器 我有一个表,我想在模式中创建一个输入,我的困难实际上是如何正确使用选择器来访问 ---更新--- 非常感谢你们的回答,但你们还没有解决它。我了解到html5还不支持作用域 我在th:$('th[class=“update”]”)中插入了一个class=“update” 但这还不起作用。行将专门查看表元素,然后在这些元素中,查找类名称。行。我相信对于您的情况,您希望在表元素中查找嵌套的.row类,因此应该将其更改为$('table th')。我不确定范围是什
---更新---
非常感谢你们的回答,但你们还没有解决它。我了解到html5还不支持作用域
我在th:$('th[class=“update”]”)中插入了一个class=“update”
但这还不起作用。行
将专门查看表
元素,然后在这些元素中,查找类名称。行
。我相信对于您的情况,您希望在表
元素中查找嵌套的.row
类,因此应该将其更改为$('table th')
。我不确定范围
是什么属性,但如果要使用.row
,可以定义一个
,然后使用$('table.row')
如果确实要使用属性scope
,还可以在jQuery中通过执行${'th[scope=“row”]'
来访问
:
scope
是
的属性,而不是类,因此正确的语法应该是$('th[scope=“row”]”)
。在代码段中,我使用此方法选择了此特定的th
,并更改了文本的颜色,例如:
$('th[scope=“row”]).css(“颜色”、“红色”);
身份证件
编辑
123
您可能想看看。
属性具有特定值的元素可以通过[AttributeName=“desiredValue”]
选择
在您的情况下:
$('th[scope=“row”]”)
$('th[scope=“row”]”)
。HTML5不支持属性scope
。有人刚刚否决了所有答案。为什么?它们和问题一样有用。我不明白否决的原因。我正在从所有答案中学习。我再次检查,发现他在使用scope
哈哈,我刚刚更新了我的答案xDI假设scope被他正在使用的框架,因为它不是一个标准的HTML标记。@Barmar实际上,HTML5不支持它。当然${'th[scope=“row”]')
应该是$('th[scope=“row”]'))
我更新了我的问题,请参见我更新了我的问题,请参见我更新了我的问题,请see@Gislef,我已经更新了我的答案。我更新了我的问题,请参阅
<table>
<thead>
<tr>
<th>ID</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">123</th>
<th><a href="" data-toggle="modal" data-target="#formModal"><span class="oi" data-glyph="pencil"></span></a></th>
</tr>
</tbody>
</table>
<div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal Form</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" style="padding:100px">
<div id="dvInputsUpdate"></div>
<button name='btn-update' type="submit" class="btn btn-primary">Atualizar</button>
</form>
</div>
</div>
</div>
</div>
$(document).on('click', '#formModal', function() {
var inpId = 0;
$('#dvInputsUpdate').html('');
$('table.row', function() {
var chkValue = $(this).closest('th').next('td').text();
$('#dvInputsUpdate').append($('<div class="form-group"><label >ID</label><input type="text" id="' + ("input" + inpId) + '" value="' + chkValue + '" /></div>'));
inpId++;
});
return false;
});
var thScopeRow = $('th[scope="row"]');