开发者

Replace a keyword in href with an input value

开发者 https://www.devze.com 2023-02-06 07:01 出处:网络
I am trying to replace a particular keyword in a href attribute which is taken from an input field. The code is as follows.

I am trying to replace a particular keyword in a href attribute which is taken from an input field. The code is as follows.

// Script

$('#fileName').blur(function() {
var saveName = $('#f开发者_StackOverflow社区ileName').val();
var appendName = $('#exportFilename').attr("href").replace(/\DEFAULTNAME/g, saveName);
$('#exportFilename').attr("href", appendName);
});

// HTML

<input type="text" id="fileName" />
<a id="exportFilename" href="http://127.0.0.1/DEFAULT/REPORTER/typDatabaase.FileName=DEFAULTNAME&typDataase.SelectId-1,2">Download File</a>

Thanks in advance

JsFiddle Link


The code you have seems to be working for me using the latest version of jQuery.
The only thing I can suggest is to ensure your jQuery is encapsulated between either $(document).ready(function() {}) or $(function() {}). Also, you may want to check to make sure you have the most up-to-date version of jQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消