Html使文本可点击而不会超链接 [英] Html make text clickable without making it a hyperlink

查看:1040
本文介绍了Html使文本可点击而不会超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新使用html和javascript。我想添加能够选择点击某些文本并执行正确的JavaScript。有没有我可以看的任何参考代码,或者一个可以帮助我的教程?

I'm very new to using html and javascript. I want to add the ability to have the option to click on certain text and have the correct javascript execute. Are there any reference code I can look at, or a tutorial that can help me?

推荐答案

对于语义我会使用<按钮> 标记像这样:

for semantics I'd use a <button> tag like this:

  <button class="link">Clicky</button>

使按钮看起来像普通文本,您可以使用css:

to make the button look like normal text you can use css:

  button.link { background:none;border:none; }

为了便于处理点击,我会使用jquery,像这样:

and for easiness of handing click I'd use jquery like so:

$(".link").click(function(){
    //your JS here
});

但是如果你在按钮上有一个ID,你可以使用普通的JS:

but if you have an ID on the button you can use plain JS like this:

var button = document.getElementById("your-button-id");
button.onclick = function(){
  //do stuff
}

这篇关于Html使文本可点击而不会超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆