Javascript 基于文本框值的URL-多行
我使用以下代码使用文本框转到url,并在url末尾添加文本框的值 我想将其更改为多行文本框。然后,对于文本框中的每一行,打开一个新的浏览器选项卡,其中包含预设的url以及末尾的行值 例如,如果我在导航到的文本框中输入“test”,则在该分钟 本质上,我只想将一个名称列表复制到一个multime文本框中,并让它每行打开一个浏览器选项卡。有人能帮我指出正确的方向吗Javascript 基于文本框值的URL-多行,javascript,jquery,html,Javascript,Jquery,Html,我使用以下代码使用文本框转到url,并在url末尾添加文本框的值 我想将其更改为多行文本框。然后,对于文本框中的每一行,打开一个新的浏览器选项卡,其中包含预设的url以及末尾的行值 例如,如果我在导航到的文本框中输入“test”,则在该分钟 本质上,我只想将一个名称列表复制到一个multime文本框中,并让它每行打开一个浏览器选项卡。有人能帮我指出正确的方向吗 <form id = "your_form" onsubmit="yourFunction()"> <inpu
<form id = "your_form" onsubmit="yourFunction()">
<input type="text" name="name">
<input type="submit" value="Search">
</form>
<script>
function yourFunction(){
var action_src = "https://www.myprofiles.co.uk/" +
document.getElementsByName("name")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}
</script>
函数yourFunction(){
var action_src=”https://www.myprofiles.co.uk/" +
document.getElementsByName(“名称”)[0]。值;
var your_form=document.getElementById(“your_form”);
你的_form.action=action\u src;
}
您可以这样做。将TextBox替换为TextArea并向按钮添加侦听器。该按钮需要有相应的ID。我添加了event.preventDefault()代码>以防止表单实际执行POST。但是如果你需要它,只需将其移除即可
<form id="your_form">
<textarea name="name"></textarea>
<input type="submit" value="Search" id="your_button">
</form>
<script>
document.getElementById("your_button").addEventListener("click", function (event) {
var action_src = "https://www.myprofiles.co.uk/?name=";
//get the value of the textarea and split by line
var rows = document.getElementsByName("name")[0].value.split(/\r?\n/);
//loop all the rows
for (var i = 0; i < rows.length; i++) {
//open a new window, could be blocked by browsers
window.open(action_src + rows[i], "Window" + i);
}
//block the posting of the form if needed
event.preventDefault();
});
</script>
document.getElementById(“您的_按钮”).addEventListener(“单击”),函数(事件){
var action_src=”https://www.myprofiles.co.uk/?name=";
//获取textarea的值并按行分割
var rows=document.getElementsByName(“名称”)[0].value.split(/\r?\n/);
//循环所有行
对于(变量i=0;i
您可以这样做。将TextBox替换为TextArea并向按钮添加侦听器。该按钮需要有相应的ID。我添加了event.preventDefault()代码>以防止表单实际执行POST。但是如果你需要它,只需将其移除即可
<form id="your_form">
<textarea name="name"></textarea>
<input type="submit" value="Search" id="your_button">
</form>
<script>
document.getElementById("your_button").addEventListener("click", function (event) {
var action_src = "https://www.myprofiles.co.uk/?name=";
//get the value of the textarea and split by line
var rows = document.getElementsByName("name")[0].value.split(/\r?\n/);
//loop all the rows
for (var i = 0; i < rows.length; i++) {
//open a new window, could be blocked by browsers
window.open(action_src + rows[i], "Window" + i);
}
//block the posting of the form if needed
event.preventDefault();
});
</script>
document.getElementById(“您的_按钮”).addEventListener(“单击”),函数(事件){
var action_src=”https://www.myprofiles.co.uk/?name=";
//获取textarea的值并按行分割
var rows=document.getElementsByName(“名称”)[0].value.split(/\r?\n/);
//循环所有行
对于(变量i=0;i
谢谢,但是这只会打开顶行url。请参阅我的更新窗口。打开(操作\u src+行[i],“窗口”+i)代码>,我认为它会有帮助。工作非常好。唯一的问题是。如果我有三行内容,我必须按三次按钮。有没有一种方法可以修改为只点击一次按钮并打开所有行的选项卡,而不是一次只打开一行?好的,似乎不起作用。万一我弄错了,我会检查的。我也检查了一遍。如果我在文本区域中输入多行,它会打开正确的窗口。谢谢,但是这只会打开最上面一行的url。请参阅我的更新window.open(action_src+rows[I],“window”+I)代码>,我认为它会有帮助。工作非常好。唯一的问题是。如果我有三行内容,我必须按三次按钮。有没有一种方法可以修改为只点击一次按钮并打开所有行的选项卡,而不是一次只打开一行?好的,似乎不起作用。万一我弄错了,我会检查的。我也检查了一遍。如果在文本区域中输入多行,将打开正确的窗口。