我有一个生成一些随机字符串的 javascript,我想用 jQuery 重写:
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$%^&*()_+";
var string_length = 8;
var randomStr = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomStr += chars.substring(rnum,rnum+1);
}
document.getElementById('randomfield').innerHTML=randomStr;
}
是否可以将它包装成这样的东西 $('.classname').click(function()