今天在写代码中遇到一个这样的问题。关于点击在html中添加点击事件,顺便把this对象通过参数传过去。

<a href='#' \>查看详情</a>    <a href='javascript:markResolve(this);' \>标记解决</a>    <a href='#' \>同步</a>

但是这样写传过去的对象不是我想要的对象,该对象中数据个数为0,没有任何内容。然后找找资料,这样写就可以了

<a href='#' \>查看详情</a>    <a href='javascript:void(0);' onclick='markResolve(this);'\>标记解决</a>    <a href='#' \>同步</a>

JS代码如下:

JQuery:

1 function markResolve(o) {
2     var text = $(o).parent().html();
3     alert(text);
4 }

JavaScript:

1 function markResolve(o) {
2     alert(o.parentNode.innerHTML);
3 }

 

相关文章:

  • 2022-03-09
  • 2021-10-06
  • 2021-09-10
  • 2021-07-01
  • 2021-06-17
  • 2021-11-26
猜你喜欢
  • 2021-09-15
  • 2021-08-15
  • 2021-12-17
  • 2022-01-06
相关资源
相似解决方案