Created
February 25, 2013 05:36
-
-
Save keelii/5027977 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
var insertRandom = function(sign) { | |
// 默认给含[diy-random] class 的元素添加点击事件 | |
var class_name = sign || 'diy-random'; | |
$('.' + class_name).livequery('click', function(e) { | |
var $this = $(e.target), | |
href = $(this).attr('href'), | |
random = (+new Date()), res; | |
if ( href.indexOf('?')>-1 ) { | |
if (/rom/.test(href)) { | |
res = href.replace(/rom=\d+$/, 'rom=' + random); | |
} else { | |
res = href + '&rom=' + random; | |
} | |
} else { | |
res = href + '?rom=' + random; | |
} | |
$this.attr('href', res); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment