javascript - 如何将元素对象作为参数发送到没有 ID 的 javascript 函数
问题描述
在 ClickedRow 函数中,我想使用正在单击的“a”。所以我想将它作为参数接收。
<td ...... >
<span class="......>
<span onmousedown="event.cancelBubble = true">
<a class="GridLinkRenderer" href="javascript:ClickedRow(this)" onclicklink="javascript:ClickedRow(this)" urlText="XXXX">
<td ......
<span class="......>
<span onmousedown="event.cancelBubble = true">
<a class="GridLinkRenderer" href="javascript:ClickedRow(this)" onclicklink="javascript:ClickedRow(this)" urlText="XXXXX">
基于 clicked<a ....>
我想通过函数 ClickedRow(this)隐藏/显示它(或<a class= "GridLinkRenderer"
在 other中显示/隐藏下一个)。<td ...>
我该怎么做 ?
我试图发送点击的 $(row).next().eq(0).tagName 和row.style.display = 'none'
,它说它是“未定义的”。
function ClickedRow(row){
$(row).next().eq(0).hide();
$(row).hide();
}
解决方案
所以复制了你的样本并想出了这个。;) 试试这个.. 并确保你明白这里发生了什么。
$(() => {
$("body").on("click",".GridLinkRenderer", (e) => {
e.preventDefault();
//works on the first link.. stil misses a few check..
//for example do we have the next td.. at all..
console.log($(e.currentTarget).closest('td').next('td').find('.GridLinkRenderer'));
})
});
推荐阅读
- r - 将excel表上传到R时如何转换日期?
- node.js - 如何在猫鼬中执行“每个”查询
- java - Java - 相对于 JFrame 的光标位置
- node.js - ng e2e 失败,因为 chrome 驱动程序下载位置变得无法访问
- python-3.x - 实现一个函数,将一个数字四舍五入到最接近的能被 X 整除的数字
- react-native - react-navigation 启用滑动以返回 android
- linq - 我有 Linq 的问题。哪里没找到
- r - 是否使用 r 中的插入符号训练了 glmnet 模型中原始尺度的变量系数
- javascript - 如何根据d3中的第三列给出颜色?
- reactjs - 在组件更新时在 Redux 中保存 React 组件滚动位置