开发者

How Call link tag by id by javascript?

开发者 https://www.devze.com 2023-01-13 08:05 出处:网络
<im开发者_开发问答g src=\"images/icon2.png\" border=0 onClick=\"window.document.getElementById(\'loadimg\')\">
   <im开发者_开发问答g src="images/icon2.png" border=0 onClick="window.document.getElementById('loadimg')">

<a href="images/img.jpg" id='loadimg'></a>

i want when click the image will active the link by id='loadimg' how can i do i try write onClick="window.document.getElementById('loadimg')" but not work

Than you


You can put the image in the link:

<a href="images/img.jpg" id='loadimg'>
    <img src="images/icon2.png" border="0" />    
</a>


It seems you want the item in the link to be loaded so something like this should work:

window.location.href = window.document.getElementById('loadimg').href;

This will cause the broswer page to navigate to this url.

Or was there something else you wanted to do?

0

精彩评论

暂无评论...
验证码 换一张
取 消