<td>
<a href='https://example.com/test/VALUEFROMINPUTHERE'>
<button id="click" onclick="click()">Click this Button</button>
</a>
</td>
并为您的输入提供 ID:
<td>
<input value="Input text Here..." id="input">
</td>
并添加 JS:
function click() {
let val = document.getElementById("input").value
window.location.href = "https://www.google.com/search?q=" + val
}
我在这里所做的就是获取输入的值,并将窗口的 href 更改为想要的单词,还要确保在添加输入值之前添加 "https://www.google.com/search?q=" 来在 google 中搜索该单词。
There is not way to get input value only using HTML... give your button an onclick attribute:
<td>
<a href='https://example.com/test/VALUEFROMINPUTHERE'>
<button id="click" onclick="click()">Click this Button</button>
</a>
</td>
and your input an ID:
<td>
<input value="Input text Here..." id="input">
</td>
and add JS:
function click() {
let val = document.getElementById("input").value
window.location.href = "https://www.google.com/search?q=" + val
}
All I'm doing here is geting the input's value, and changing the window's href to the wanted word, also making sure the word is being searched in google by adding the "https://www.google.com/search?q=" before adding the value of the input.
在此代码中,当单击 a 标签时,它会触发一个 JS 函数,该函数会获取 id 为“value”的输入值,并通过将其值与 window.open( ) 功能。
<input type="text" placeholder="Enter Text" id="value" />
<a href="#" onClick="openLink()">Click Me</a>
<script>
function openLink() {
let value = document.getElementById("value").value
window.open(`https://www.example.com/${value}`)
}
</script>
In this code, when the a tag is clicked, it triggers a JS function that grabs the value of the input with the id "value" and opens thee link with by concatenating it's value to the end of the URL with the window.open() function.
<input type="text" placeholder="Enter Text" id="value" />
<a href="#" onClick="openLink()">Click Me</a>
<script>
function openLink() {
let value = document.getElementById("value").value
window.open(`https://www.example.com/${value}`)
}
</script>
发布评论
评论(2)
仅使用 HTML 无法获取输入值...为您的按钮提供 onclick 属性:
并为您的输入提供 ID:
并添加 JS:
我在这里所做的就是获取输入的值,并将窗口的 href 更改为想要的单词,还要确保在添加输入值之前添加
"https://www.google.com/search?q="
来在 google 中搜索该单词。There is not way to get input value only using HTML... give your button an onclick attribute:
and your input an ID:
and add JS:
All I'm doing here is geting the input's value, and changing the window's href to the wanted word, also making sure the word is being searched in google by adding the
"https://www.google.com/search?q="
before adding the value of the input.在此代码中,当单击 a 标签时,它会触发一个 JS 函数,该函数会获取 id 为“value”的输入值,并通过将其值与 window.open( ) 功能。
In this code, when the a tag is clicked, it triggers a JS function that grabs the value of the input with the id "value" and opens thee link with by concatenating it's value to the end of the URL with the window.open() function.