gpt4 book ai didi

jquery - td 值不在很酷的 autosuggest jQuery 函数中

转载 作者:行者123 更新时间:2023-12-01 07:41:32 25 4
gpt4 key购买 nike

我正在尝试访问coolautosuggest函数内的td值,但它给出未定义的值

HTML 代码:

<table class="table table-bordered cust_job_over">
<thead>
<tr>

<th>Skillset</th>
<th>Assignee</th>

</tr>
</thead>
<tbody class="LabourTbody">
<tr>

<td width="45%">
<input type="hidden" class="labourAssetID" value="31" name=""><span class="skill">0.35m Planer Operator</span></td>
<td width="40%" style="position: relative;">
<input type="hidden" class="" value="167,169,172,173" name="">
<input type="text" class="form-control cool-auto-suggest" style="width: 90% !important;float:left;">
<div class="assig_noti assign_complete cust_job_over_noti"></div>
</td>

</tr>
<tr>

<td width="45%">
<input type="hidden" class="labourAssetID" value="33" name=""><span class="skill">Sweeper Driver (CE)</span></td>
<td width="40%" style="position: relative;">
<input type="hidden" class="" value="167,169,172,173" name="">
<input type="text" class="form-control cool-auto-suggest" style="width: 90% !important;float:left;">
<div class="assig_noti assign_complete cust_job_over_noti"></div>
</td>

</tr>


</tbody>
</table>

JQUERY 代码:

$(document).ready(function() {
$(".cool-auto-suggest").coolautosuggest({
url: window.location.origin + "/datalist/",
showThumbnail: true,
showDescription: true,
additionalFields: {
"/asset": $(this).closest('tr').find('td:eq(0) .labourAssetID')
},
onSelected: function(result) {

}
});
});

这是我得到未定义值的地方"/asset": $(this).closest('tr').find('td:eq(0) .labourAssetID')

This is the plugin 我正在尝试实现它。

有人可以建议我如何在该函数内使用类名获取最接近的td输入值吗?

最佳答案

问题是 $(this) 引用了文档对象,因为您位于 $(document).ready() 事件的上下文中。

如果您有多个 cool-auto-suggest 类,则需要迭代每个元素:

$(document).ready(function() {
$(".cool-auto-suggest").each(function() {
// Here I save reference to the current iterated object
var $el = $(this);

// Here I calling the plugin separately, for each '.cool-auto-suggest'
$el.coolautosuggest({
url: window.location.origin + "/datalist/",
showThumbnail: true,
showDescription: true,
additionalFields: {
// Here I select the correct element using the reference ($el)
"/asset": $el.closest('tr').find('td:eq(0) .labourAssetID')
},
onSelected: function(result) {

}
});
});
});

关于jquery - td 值不在很酷的 autosuggest jQuery 函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46895276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com