Javascript打开URL +用户输入的文本

Kar*_*sca 1 javascript url

这可能吗?

我有输入框和提交按钮.

  1. 用户将输入他们的"参考编号"(例如:"hello123")
  2. 用户将单击"提交"按钮.
  3. 单击提交按钮后,javascript将在新浏览器选项卡中打开url链接,其中包含url链接(我已分配)以及用户输入(即hello123)

分配的网址是:www.mywebsite.com/点击提交按钮后,通过javascript打开的网址是:www.mywebsite.com/print/hello123/

d.y*_*yuk 7

查看演示:http://jsfiddle.net/Gv5bq/

HTML:

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" />
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#btn").click( function() {
    var url = "http://www.mywebsite.com/print/" + $("#text").val();
    window.open(url);
});
Run Code Online (Sandbox Code Playgroud)

更新:(简单JS版) http://jsfiddle.net/Gv5bq/1/

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value);" />
Run Code Online (Sandbox Code Playgroud)