gpt4 book ai didi

javascript - 我想建立一个链接,其中 href 依赖于 js 变量

转载 作者:行者123 更新时间:2023-12-02 21:46:57 25 4
gpt4 key购买 nike

我弄清楚了整个innerhtml的事情,但我不知道如何将变量添加到href中。我希望它建立一个链接,其中的标题是您输入的标题,并且当您单击“创建”时,您在 href 中输入的 javascript 会包含在内。

<div class="title">
Bookmarklet Maker
<br>
<br>
<input size="13" onkeypress="return searchKeyPress(event);" name="getTitle" type="text" id="getTitle" style="background-color: #252525; border: 2px; border-style: double; border-color: white; color: white; padding: 15px 32px; text-align: left; text-decoration: none; display: inline-block; font-size: 16px; font-weight: bold; margin: 4px 2px; cursor:;"
placeholder="Bookmarklet name" />
<br>
<input size="40" onkeypress="return searchKeyPress(event);" name="geJs" type="text" id="getJs" style="background-color: #252525; border: 2px; border-style: double; border-color: white; color: white; padding: 15px 32px; text-align: left; text-decoration: none; display: inline-block; font-size: 16px; font-weight: bold; margin: 4px 2px; cursor:;"
placeholder="Javascript" />
<br>
<button style="background-color: #252525;
border: 2px;
border-style: solid;
border-color: white;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 4px 2px;
cursor: pointer;" id="bookmarkletbutton" onclick="createBookmarklet()">Create</button>
<script>
function createBookmarklet() {
var title_input = document.getElementById('getTitle').value;
var js_input = document.getElementById('getJs').value;
document.getElementById('title').innerHTML = title_input;
document.getElementById('js').innerHTML = js_input;
}
</script>
<br>
<br>
<a class="link" href="" id="title"></a>
</div>

最佳答案

您可以设置href ruby 通过 <element>.setAttribute("href", <value>)
-> document.getElementById("title").setAttribute("href", js_input)
(正如大卫提到的: <element>.title = <value> 也有效)

关于javascript - 我想建立一个链接,其中 href 依赖于 js 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60229798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com