//下拉框获取值
<select id="deptSelect" οnchange="deptChange()">
<option value="0">全市</option> </select> alert($('#deptSelect').val()); alert($("#deptSelect").find("option:selected").text());
//时间格式化 function smartTimeAgo(date){ var time=new Date().getTime(); time=parseInt((time-date)/1000); var s=""; if(time<60*10){ //十分钟内 return '刚刚'; }else if((time<60*60)&&(time>=60*10)){ //超过十分钟少于1小时 s = Math.floor(time/60); return s+"分钟前"; }else if((time<60*60*24)&&(time>=60*60)){ //超过1小时少于24小时 s = Math.floor(time/60/60); return s+"小时前"; }else if((time<60*60*24*3)&&(time>=60*60*24)){ //超过1天少于3天内 s = Math.floor(time/60/60/24); return s+"天前"; }else{ //超过3天 var date= new Date(parseInt(date)); return date.getFullYear()+"/"+(date.getMonth()+1)+"/"+date.getDate(); } }
/*关键词检索高亮标出 *param idHtmlContent 需要检索的HTML内容ID *param keyword 关键字,多个以空格隔开 */ function keywordHighlight(idHtmlContent,keyword) { var content= $("#"+idHtmlContent).html();//获取内容 if ($.trim(keyword)==""){ return;//关键字为空则返回 } var htmlReg = new RegExp("\<.*?\>", "i"); var arrA = new Array(); //替换HTML标签 for (var i = 0; true; i++) { var m = htmlReg.exec(content); if (m) { arrA[i] = m; }else { break; } content = content.replace(m, "{[(" + i + ")]}"); } words = unescape(keyword.replace(/\+/g, ' ')).split(/\s+/); //替换关键字 for (w = 0; w < words.length; w++) { var r = new RegExp("(" + words[w].replace(/[(){}.+*?^$|\\\[\]]/g, "\\$&") + ")", "ig"); content = content.replace(r, "<b><span style='color:red;font-size:14px;'><u>"+words[w]+"</u></span></b>");//关键字样式 } //恢复HTML标签 for (var i = 0; i < arrA.length; i++) { content = content.replace("{[(" + i + ")]}", arrA[i]); } $("#"+idHtmlContent).html(content); }