Javascript 使用jQuery将URL转换为其他附属URL
我有下面的示例代码。当用户添加affid和URL时,他们可以将URL转换为特定格式Javascript 使用jQuery将URL转换为其他附属URL,javascript,jquery,Javascript,Jquery,我有下面的示例代码。当用户添加affid和URL时,他们可以将URL转换为特定格式 Affid <input type="text" id="affid"> URL <input type="text" id="url"> <button id="convert">Convert</button><br> <hr> <h4>output</h4> <inp
Affid
<input type="text" id="affid">
URL
<input type="text" id="url">
<button id="convert">Convert</button><br>
<hr>
<h4>output</h4>
<input type="text" id="output"> <button id="select">Select</button>
<br>
<strong>Input:</strong> http://www.flipkart.com/asus-zenfone-4-a400cg/p/itmeygpv4uxt4gjx?pid=MOBDXZ9WQFBAY2XX<br>
<strong>Output:</strong> http://dl.flipkart.com/dl/asus-zenfone-4-a400cg/p/itmeygpv4uxt4gjx?pid=MOBDXZ9WQFBAY2XX&affid=waz<br>
如果用户输入affId waz和url
输出应该是
退房
从您的小提琴来看,我假设您将使用jQuery。如果不需要jQuery,只需将jQuery选择器更改为getElementById即可
函数获取字段并在输出框中进行操作和显示
HTML中的更改
预期的输入/输出是什么?能否提供JSFIDLE链接?更新的链接。。对不起,不客气。从今往后,请你的问题再清楚一点。花了一些时间来弄清楚你想要什么!
function ConvertURL(){
var URL = $("#url").val();
var Affid = $("#affid").val();
URL = URL.replace("www","dl");
var position = URL.indexOf(".com");
URL = [URL.slice(0, position+5), "dl/", URL.slice(position+5)].join('');
var convertedURL = URL+"&affid="+Affid;
$("#output").val(convertedURL);
}
<button id="convert" onclick="ConvertURL()">