栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何创建一个类似于链接的HTML按钮?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何创建一个类似于链接的HTML按钮?

的HTML

纯HTML方式是将其放入

<form>
,您可以在其中指定所需的目标URL
action

<form action="https://google.com">    <input type="submit" value="Go to Google" /></form>

如有必要,请

display: inline;
在表单上设置CSS ,以使其与周围的文本保持一致。除了
<inputtype="submit">
上面的示例,您还可以使用
<button type="submit">
。唯一的区别是该
<button>
元素允许孩子。

直观上,您希望能够使用

<buttonhref="https://google.com">
<a>
元素类似的元素,但不幸的是,根据HTML规范,此属性不存在。

的CSS

如果允许使用CSS,则只需使用

<a>
您设置的样式即可看起来像按钮,并使用
appearance
属性(仅Internet
Explorer不支持
)。

<a href="https://google.com" >Go to Google</a>a.button {    -webkit-appearance: button;    -moz-appearance: button;    appearance: button;    text-decoration: none;    color: initial;}

或者选择众多CSS库之一,例如Bootstrap。

<a href="https://google.com" >Go to Google</a>

的Javascript

如果允许使用Javascript,请设置

window.location.href

<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />

除了

<input type="button">
上面的示例,您还可以使用
<button>
。唯一的区别是该
<button>
元素允许孩子。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/447075.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号