/* 此方法用于所有文章搜索,只需要传递搜索关键词 */ function searcharticle(keywords) { var words = ""; //申明搜索关键词 var specialcharacter = new regexp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?_%+]"); //枚举所有特殊字符 for (var i = 0; i < keywords.length; i++) { words = words + keywords.substr(i, 1).replace(specialcharacter, ''); //剔除关键词中的特殊字符 } if (words == "" || words == null) { alert("关键词不能为空!或者特殊字符!"); } else { location.href = "/webarticle/search.html?cl=" + randomstring(8,'12346789abcdwxyzabcdwxyz') +"&bd=" + randomstring(16,'12346789abcdefghwxyzabcdefghwxyz') +"&keywords=" + encodeuricomponent(keywords) + "&key=" + randomstring(32, '0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'); //编码后在传递,以防乱码 } } function randomstring(length, chars) { var result = ''; for (var i = length; i > 0; --i) result += chars[math.floor(math.random() * chars.length)]; return result; }