[英]Convert an anchor to button
我有一个简单的问题,如何将<a href="">
转换为<button>
?
我这样做是因为我不希望用户看到链接 url。
例子:
<a href="#<?php echo $msg_id=$data['msg_id']; ?>" title="Comment" data-toggle="modal"><img src="images/comments.png"/></a>
现在我怎样才能把它转换成按钮?
<button></button>
我假设您正在使用引导程序并且您想使用<button>
触发模态。 这是引导程序文档中的示例:
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
如果我将其应用于您的代码,
<button type="button" data-toggle="modal" data-target="#<?php echo $msg_id=$data['msg_id'];?>" title="Comment"><img src="images/comments.png"/></button>
<button onclick="window.location='URL'">button text</button>
.. 但他们将能够看到检查 html 页面代码的 url!
我假设你想要做的是当按钮被点击时,它应该打开与 href 中存在的相同的 URL。 如果是这种情况,您只需向按钮添加一个 onclick 事件处理程序,即 onclick="navigate(' Your URL here ');"。
您还可以设置 onclick 事件来调用一个 javascript 函数,该函数又可以为您打开一个模态/普通弹出窗口
尝试使用这个:
<form><input type="button" value="Click me" onclick="window.location.href='http://www.google.ch/'" /></form>
把你想要的文本作为value
,把你的 URL 放在window.location.href=''
。
如果你想要它<button></button>
这可能是另一种方式:
<button onclick="window.location.href='http://www.google.ch/'">Click me</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.