简体   繁体   English

jQuery单击隐藏的元素

[英]Jquery click on hidden element

I have 我有

<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>

I want to make click on the element that rises when onmouseover="artifactAlt(this,event,2)" is firing, how to do that? 我想单击onmouseover="artifactAlt(this,event,2)"触发时上升的元素, onmouseover="artifactAlt(this,event,2)"怎么做?

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

i get undefined and nothin happens. undefined ,什么都没发生。

You should use .click() method. 您应该使用.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> 

You should try jquery trigger 's as follows 您应该尝试使用jquery 触发器 ,如下所示

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

Usage of trigger('click') will save you one function call as jQuery internally calls trigger for a $().click() function call as pointed out in this post. 触发器的使用在jQuery内部调用触发的$(“点击”)会为你节省一个函数调用()。点击()函数调用中指出职位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM