Created
March 23, 2013 22:20
-
-
Save rbao/5229559 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
function appendParamsToUrl(url, params) { | |
var new_url = url; | |
if (url.indexOf('?') == -1) | |
new_url += '?' | |
for (key in params) | |
new_url += '&' + key + '=' + params[key] | |
return new_url | |
}; | |
$.fn.dyanamic_link = function(selectors) { | |
var params = {}; | |
var original_href = $(this).attr('href'); | |
var new_href | |
$(this).click(function(e) { | |
e.preventDefault(); | |
$(selectors).each(function() { | |
key = $(this).attr('name'); | |
value = $(this).val(); | |
params[key] = value; | |
}); | |
new_href = appendParamsToUrl(original_href, params); | |
window.location = new_href; | |
}); | |
return $(this); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment