#全局CSS替换 Jquery
$(".values").css("color","green");
//先删除,后添加。或者先添加后删除均可
$(".aaa").addClass("bbb").removeClass("aaa");
$(".aaa").removeClass("aaa").addClass("bbb");
/***** 格式化整个Form,转换成JSON格式 *****/
function getJsonForm( formId ){
if( varIsNUll( formId ) ){
formId = "defaultFormId" ;
}
console.log($('#' + formId ).serializeJSON());
console.log(JSON.stringify($('#' + formId ).serializeJSON()));
return JSON.stringify($('#' + formId ).serializeJSON());
}
/***** 判断对象是否为空 *****/
function varIsNUll( reValue ){
if (typeof(reValue) == "undefined" || reValue== null || reValue.length == 0 ) {
return true ;
}else{
return false ;
}
}
格式化JSON字符串 to JSON
var data = '{"status":"0","id":"14","filePath":"http://zcsjw-com.oss-cn-qingdao.aliyuncs.com/photo/common/supplier/pic/140199734915.png"}' ;
var json = JSON.parse(data);
console.log( json.filePath);
JS只取Double的两位小数
(sum / dayCount).toFixed(2)
限制只能保留两位小数点
<input type="text" onkeyup="num(this)" size="10"/>元
function num(obj){
obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
}
限制只能输入数字
<input type="text" onkeyup='this.value=this.value.replace(/\D/gi,"")'/>
//公共日志组件
log = function (s) {
try {
console.log(s);
} catch (e) {}
}
去掉A链接下划线样式:
a{text-decoration:none}
JSTL判断是否是最后一个元素
<c:forEach items="${pointSection}" var="chl" varStatus="stat">
<c:if test="${!stat.last}" >
<div class="item" id="_MYJD_repair" style="border-bottom-style: dotted;border-bottom-width: 1px;border-bottom-color: olive">
<a href="pointProductController.html?flag=flagPProductsection${chl.pointseId}" class="zltda">${chl.section}</a>
</div>
</c:if>
<c:if test="${stat.last}">
<div class="item" id="_MYJD_repair">
<a href="pointProductController.html?flag=flagPProductsection${chl.pointseId}" class="zltda">${chl.section}</a>
</div>
</c:if>
</c:forEach>
判断属性否为空
<c:if test="${empty var1}">
var1 is empty or null.
</c:if>
<c:if test="${not empty var1}">
var1 is NOT empty or null.
</c:if>
console.info兼容IE
/****
* 打印日志,但是需要兼容IE,否则IE又执行不了
* @param msg
*/
function consoleLog(msg){
if (window["console"]){//判断是否是IE
console.log(msg);
}
}
var a = $("input[name='radio']:checked").val();