記錄下自己項目中遇到的坑點,邊做邊總結吧
- 判斷變量是否為空及變量為0的情況
Paste_Image.png
如果你的變量為0千萬要注意下
2.時間串截取改格式
beginTimes = beginTime.substring(0,4)+'-'+beginTime.substring(4,6)+'-'+beginTime.substring(6,8)+' '+beginTime.substring(8,10)+':'+beginTime.substring(10,12);
3.js移除空格,回車
var resultStr = testStr.replace(/\ +/g, ""); //去掉空格 resultStr = testStr.replace(/[ ]/g, ""); //去掉空格 resultStr = testStr.replace(/[\r\n]/g, ""); //去掉回車換行
4 限制文本框只能輸入數字
onkeyup="this.value=this.value.replace(/[^\d]/g,'') " //防止從別處粘貼 onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"