[英]How to dynamically add a link to a button?
This is tied to this question.这与这个问题有关。
How can I dynamically add an HREF as a field is filled out? 如何在填写字段时动态添加 HREF?
I had success getting the link to work but it has been decided that the link would be better as a button.我已成功使链接正常工作,但已决定该链接作为按钮会更好。 Here is what I have for the link.
这是我的链接。
The function I used我用的function
function buildPMLink(){
let urlStart = "https://www.projectmanagement.com?query=";
let urlEnd = "&showResults=False";
let campRef = document.getElementByID("campid").value;
let fullURL = urlStart + campRef + urlEnd;
document.getElementById('pmURL').href = fullURL;
}
The field that triggers the function触发 function 的字段
<div class="input-field col s3">
<input placeholder="Enter Campaign ID" id="campid" type="text" class="validate" oninput="buildWFLink(); buildPMLink();" required >
<label for="campaign_id">Campaign ID</label>
</div>
The link I added the dynamic HREF to.我添加了动态 HREF 的链接。
<div >
<a id="pmURL">Test</a>
</div>
I tried creating a button and wrapping that in a form hoping to use the form action but failed.我尝试创建一个按钮并将其包装在一个希望使用表单操作的表单中,但失败了。 What am I missing?
我错过了什么?
You can do something very simple like this:你可以像这样做一些非常简单的事情:
<a id="pmURL"><button>Test</button></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.