【问题标题】:Image to act as a button HTML用作按钮 HTML 的图像
【发布时间】:2015-02-17 14:40:16
【问题描述】:

你好,我有这个代码:

 <!-- Button that triggers the popup -->
            <button id="my-button">POP IT UP</button>
            <!-- Element to pop up -->
            <div id="element_to_pop_up">Content of popup</div>

我有这张图片:

<img src="botones/bannerdiseno_audifonosinpilas.png" width="160" height="33"  alt=""/>
</a><a href="tecnologia.html">

我想知道如何更改该图像上的链接以执行与按钮相同的操作,我应该使用什么语法,所以每当我单击图像时,它都会触发按钮操作并删除按钮本身

谢谢

【问题讨论】:

  • 您可以使用按钮并使用 css 使其看起来像图像

标签: javascript jquery html image button


【解决方案1】:
    <img onclick="document.getElementById('my-button').click()" src="botones/bannerdiseno_audifonosinpilas.png" width="160" height="33"  alt=""/>

or 

<a href="javascript: document.getElementById('my-button').click()"> <img src="botones/bannerdiseno_audifonosinpilas.png" width="160" height="33"  alt=""/></a>

【讨论】:

  • 现在,我该如何隐藏或移除按钮?因为我使用“我的按钮”调用它
  • document.getElementById('my-button').style.display='none';或使用 jQuery $('#my-button').hide()
  • 或者你可以这样做
【解决方案2】:

您可以使用input type="image"

<input type="image" src="submit.gif" alt="Submit">

【讨论】:

    猜你喜欢
    • 2019-07-29
    • 2017-12-23
    • 2018-07-22
    • 2015-10-14
    • 1970-01-01
    • 2015-04-16
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多