简体   繁体   English

将锚点转换为按钮

[英]Convert an anchor to button

I have a simple question how to convert <a href=""> to <button> ?我有一个简单的问题,如何将<a href="">转换为<button>

I do that because I don't want user to see the link url.我这样做是因为我不希望用户看到链接 url。

example :例子:

<a href="#<?php echo $msg_id=$data['msg_id']; ?>" title="Comment" data-toggle="modal"><img src="images/comments.png"/></a>

Now how can I convert that into button ?现在我怎样才能把它转换成按钮?

<button></button>

I'm assuming that you're using bootstrap and you want to trigger a modal using <button> .我假设您正在使用引导程序并且您想使用<button>触发模态。 Here's a sample from the bootstrap documentation:这是引导程序文档中的示例:

<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>

If I apply it to your code,如果我将其应用于您的代码,

<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!

I assume what you want to do is that when the button is clicked, it should open the same URL that was present in href.我假设你想要做的是当按钮被点击时,它应该打开与 href 中存在的相同的 URL。 If this is the scenario, you can just add an onclick event handler to the button ie onclick="navigate(' Your URL here ');".如果是这种情况,您只需向按钮添加一个 onclick 事件处理程序,即 onclick="navigate(' Your URL here ');"。

You can also set the onclick event to call a javascript function which in turn can open a modal/normal popup window for you您还可以设置 onclick 事件来调用一个 javascript 函数,该函数又可以为您打开一个模态/普通弹出窗口

Try to use this:尝试使用这个:

<form><input type="button" value="Click me" onclick="window.location.href='http://www.google.ch/'" /></form>

Put your text you want for value and put your URL in window.location.href='' .把你想要的文本作为value ,把你的 URL 放在window.location.href=''

If you want it with <button></button> this could be another way:如果你想要它<button></button>这可能是另一种方式:

<button onclick="window.location.href='http://www.google.ch/'">Click me</button>

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

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