简体   繁体   English

将锚标记更改为使用javascript / jquery mobile的按钮?

[英]changing anchor tag into button with javascript/jquery mobile?

I'm trying to change my anchor tag to a button and have it function properly but it seems when I change this: 我正在尝试将锚标签更改为按钮,并使它正常运行,但是当我更改此标签时,似乎出现了:

var editButton = document.createElement('a');


        editButton.href = "#additem";

this: 这个:

var editButton = document.createElement('button');


        editButton.href = "#additem";

The button when clicked, doesn't do anything. 单击该按钮后,不会执行任何操作。 If I switch it back however, the link works fine... my goal is essentially to change the anchor text into an actual jquery button. 但是,如果我将其切换回去,则链接可以正常工作……我的目标实质上是将锚文本更改为实际的jquery按钮。

I've also tried setting the attribute class to ui button but that did nothing as well. 我也尝试将属性类设置为ui按钮,但这也没做。 Any help would be greatly appreciated. 任何帮助将不胜感激。

The button does not have a property of href, what you can do is lsten to the onclick event of the button like this: 该按钮没有href属性,您可以执行以下操作来处理按钮的onclick事件:

var editButton = document.createElement('button'); 
editButton.onclick = function(e){ location.href = 'http://' + window.location.hostname + window.location.pathname +'#additem'}

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

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