简体   繁体   English

我可以为按钮创建快捷方式吗?

[英]Can I make a short cut for a button?

I have links on my web page that are called like this:我的 web 页面上有链接,名称如下:

<a href="/xxx/"  >
  <button >xxx</button>
</a> 

I have several like this and I would like to make it easy for a user to click them without the user having to go to the button and click.我有几个这样的,我想让用户可以轻松地单击它们,而用户不必 go 到按钮并单击。 Is it possible for me to give the user a shortcut such as ALT M or something like that assigned to a button?我是否可以给用户一个快捷方式,例如 ALT M 或分配给按钮的类似东西? Also can I make a button be the default if the user clicks enter?如果用户单击输入,我也可以将按钮设为默认按钮吗?

You should use the accesskey property您应该使用accesskey属性

<a href="/xxx/"  >
  <button accesskey="M" >xxx</button>
</a> 

Give the element an "accesskey" using accesskey="1".使用 accesskey="1" 给元素一个“accesskey”。 When a user presses 1 that will activate the link.当用户按 1 时,将激活链接。

EDIT编辑

For a javascript (jQuery) solution see this SO post对于 javascript (jQuery) 解决方案,请参阅 此 SO 帖子

I would recommend styling a div to look like a button as they do for the tags here on stackoverflow.com as an example我建议将 div 设置为看起来像一个按钮,就像他们在 stackoverflow.com 上的标签一样

<div class="post-taglist">
<a class="post-tag" rel="tag" title="" href="/questions/tagged/javascript">javascript</a>
<a class="post-tag" rel="tag" title="" href="/questions/tagged/html">html</a>
<a class="post-tag" rel="tag" title="" href="/questions/tagged/css">css</a>
</div>

CSS used by stackoverflow.com (needs a bit of work!) CSS 由 stackoverflow 使用。com(需要一些工作!)

.post-taglist {
    clear: both;
    margin-bottom: 10px;
}
.edit-tags-wrapper > a.post-tag {
    margin-right: 6px;
}
.post-tag, .post-text .post-tag, #wmd-preview a.post-tag {
    background-color: #E0EAF1;
    border-bottom: 1px solid #3E6D8E;
    border-right: 1px solid #7F9FB6;
    color: #3E6D8E;
    font-size: 90%;
    line-height: 2.4;
    margin: 2px 2px 2px 0;
    padding: 3px 4px;
    text-decoration: none;
    white-space: nowrap;
}
post-tag:hover, .post-text .post-tag:hover, #wmd-preview a.post-tag:hover {
    background-color: #3E6D8E;
    border-bottom: 1px solid #37607D;
    border-right: 1px solid #37607D;
    color: #E0EAF1;
    text-decoration: none;
}

Alternatively you can wrap your button in a form element like或者,您可以将按钮包装在表单元素中,例如

<form method="post" action="nextPage.html"  >
<button>Press me</button>
</form>

I hope this helps.我希望这有帮助。

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

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