【问题标题】:Jquery click on hidden elementJquery点击隐藏元素
【发布时间】:2017-02-05 14:07:36
【问题描述】:

我有

<table width="60" height="60" cellpadding="0" 
cellspacing="0" border="0" style="float: left; margin: 1px" 
background="images/data/source_red.gif">
   <tbody>
      <tr>
         <td act1="7" act3="8" store="true" art_id="4949" cnt="1" div_id="AA_4949" 
         onmouseover="artifactAlt(this,event,2)" 
         onmouseout="artifactAlt(this,event,0)" 
         valign="bottom" 
         style="background-image: url(&quot;images/d.gif&quot;); cursor: pointer;">&nbsp;</td>
      </tr>
   </tbody>
</table>

我想点击onmouseover="artifactAlt(this,event,2)"触发时上升的元素,怎么做?

当我在做$('#body').contents().find('td[art_id="4949"]')[0].click();

我收到undefined 并没有任何反应。

【问题讨论】:

  • 什么隐藏元素?我没有看到上面的任何隐藏元素(没有双关语)。

标签: javascript jquery html events


【解决方案1】:

你应该使用.click()方法。

function artifactAlt(obj,event,number){
     $(obj).click();
}

function artifactAlt(obj,event,number){
   $(obj).click();
}

$('tr').click(function(){
  alert('tr clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="60" height="60" cellpadding="0" 
cellspacing="0" border="0" style="float: left; margin: 1px" 
background="images/data/source_red.gif">
   <tbody>
      <tr>
         <td act1="7" act3="8" store="true" art_id="4949" cnt="1" div_id="AA_4949" 
         onmouseover="artifactAlt(this,event,2)" 
         onmouseout="artifactAlt(this,event,0)" 
         valign="bottom" 
         style="background-image: url(&quot;images/d.gif&quot;); cursor: pointer;">abcd</td>
      </tr>
   </tbody>
</table>

【讨论】:

    【解决方案2】:

    你应该试试 jquery trigger 的如下

    function artifactAlt(element, event, number) {
      $(element).trigger('click');
    }

    使用 trigger('click') 将为您节省一个函数调用,因为 jQuery 在内部调用了 $().click() 函数调用的触发器,正如this 帖子中所指出的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-15
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 2010-11-08
      • 2018-12-24
      相关资源
      最近更新 更多