- chrome关闭缓存:F12 在network下选中 disable Cache
- <button> 标签默认type=submit,如果选择用js提交应把type=button
- <select>标签提示“请选择” ,且选项中不出现此项: <option value='' style='display:none' >请选择要预约的部门</option>
- <select>修改选项触发时间用change()
- js表格插件:datatable
- 链式写法会方便很多:$("#legel-logo").removeClass("leg").addClass("cur");
- ajax返回json,:
function serchService(dptId,userType){
$.ajax({
url : "service.action",
type : "post",
dataType : 'json',
data : {
fn:'getCategory',
userType:userType,
pageNum:1,
pageSize:99,
isWeb :0,
addType:"",
deptId :dptId
},
success : function(response){
var json= response.data;
if(response.total!=undefined && response.total>0){
setCategoryListData(json,userType); //对返回json进行处理
}else{
$("#page").html("");
$("#tab_main").html("<option value='0'>未找到主题服务!</option>");
}
}
});
}
function setCategoryListData(json,type) {
var curId = type==1?"service":"service-legel";
if(json!= null && json.length>0){
var gerenHtml = "";
var serviceChecked = false;
if($("parentUnid").val() !=null && $("parentUnid").val()!=""){
serviceChecked = true;
}
for(var i=0;i<json.length;i++) {
if(i==0){
gerenHtml += "<option value='' style='display:none' >请选择事项</option>";
}
gerenHtml = gerenHtml
+ "<option value='" + json[i].unid + "'> " + json[i].name + "</option>";
}
$("#" + curId).html(gerenHtml);
return;
}
}
- 日期时间格式化
Date.prototype.format = function (format) {
/*
* 使用例子:format="yyyy-MM-dd hh:mm:ss";
*/
var o = {
"M+": this.getMonth() + 1, // month
"d+": this.getDate(), // day
"h+": this.getHours(), // hour
"m+": this.getMinutes(), // minute
"s+": this.getSeconds(), // second
"q+": Math.floor((this.getMonth() + 3) / 3), // quarter
"S": this.getMilliseconds()
// millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
- RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
调用:
var d1 = new Date();
d1.format('yyyy-MM-dd');
var d2 = new Date();
d2.format('yyyy-MM-dd');
正则表达式,不使用new RegExp()
//正数正则
var posPattern = /^\d*\.?\d+$/;
//负数正则
var negPattern = /^-\d*\.?\d+$/;
//数字正则
var numPattern = /^-?\d*\.?\d+$/;
console.log(posPattern.test("42.2"));
console.log(negPattern.test("-42.2"));
console.log(numPattern.test("-42.2"));
-
select做出input的placeholder效果
image.png -
js的escape和unescape方法
对特殊字符进行编解码
<script type="text/javascript">
var a = escape("Visit W3School.>#$com.cn!");
document.write(a) + "<br />")
document.write(unescape(a));
</script>
执行结果:
Visit%20W3School.%3E%23%24com.cn%21
Visit W3School.>#$com.cn!
网友评论