【发布时间】:2020-07-02 15:02:50
【问题描述】:
我正在使用危险的 kendo-ui,这使得添加选择器成为一场噩梦;无论如何我试图简单地单击输入复选框元素只需获取 id 选择器的内部内容,我需要介于 ( 和 ) 之间。在括号之间。
带有kendo ui的复选框嵌套在<li>标签中,并且在选中时似乎没有更改为.checked,我注意到li的aria-checked在选中时确实更改为'true',所以我我正在尝试将其用作句柄。
我在下面的父li标签上成功添加了事件监听器:
let chkst = document.querySelector('#shake-tree li.k-item');
if (chkst) {
chkst.addEventListener("click", filterByID);
} else {
getCur();
}
在我的filterByID 函数中,我尝试搜索选中状态并获取 id 内容和正则表达式到内括号。下面只是控制台日志什么都没有,所以要么没有正确检测到aria-checked,要么伪选择器不起作用。
....
let idChkBoxes = document.querySelectorAll(`#shake-tree li.k-item`);
idChkBoxes.forEach(function (node) {
console.log(node); <---- this consoles as the below html screenshot, same
if (node.getAttribute("aria-checked") === true) {
let s = $(node + ">" + "input[type='checkbox']");
let sID = s.getAttribute("id");
console.log(s);
let idStr = sID.split(/[()]/);
sqlExp += "'" + idStr + "' ";
}
});
........
也试过这个:
if ($(node).attr('aria-checked') === "true"){
console.log(node);
........
这是标记的屏幕截图:
正如您在上面的标记中看到的 ^ 我需要的 id 也在 span.k-in 元素的内部文本中,因此如果需要也可以在那里抓取,但似乎更难访问。
我的目标是为每个选中的复选框插入(..) 括号id,并在每次选中复选框时重新检查。
【问题讨论】:
-
您是否在此处使用带有复选框的剑道树形视图?
-
是剑道树视图复选框
标签: javascript jquery kendo-ui