核心:
一,创建元素:
var ul=document.createElement("ul"); ul.setAttribute("id",id) ul.setAttribute("class","audit-ul"); ul.style.cssText="left:"+left+"px;top:"+top+"px;"
二,为元素绑定事件兼容写法:
var Browser_Name = navigator.appName; var is_IE = (Browser_Name == "Microsoft Internet Explorer"); //判读是否为ie浏览器 if (is_IE) { a.attachEvent("click", function () { auditP(this,id); }); } else { a.addEventListener("click", function () { auditP(this,id); }, false); }
三,正则输入的价格,非负,保留两位小数;
var reg = /^(?!0+(?:.0+)?$)(?:[1-9]d*|0)(?:.d{1,2})?$/; var cashPrice = jQuery("input[name='cash_price']").val(); reg.test(cashPrice); //console.log(true或者false)
预览地址:
https://besswang.github.io/audit-demo/