Replace a keyword in href with an input value
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.
精彩评论