JS 通用常用方法comm类
/**
* 常用JS 通用类
* author:panfu
*/
/**
* 去掉前后空格
* " dd ".trim(); == "dd"
*/
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
/**
* 去掉左空格
* " dd".leftTrim(); == "dd"
*/
String.prototype.leftTrim = function() {
return this.replace(/(^\s*)/g, "");
}
/**
* 去掉右空格
* "dd ".rightTrim(); == "dd"
*/
String.prototype.rightTrim = function() {
return this.replace(/(\s*$)/g, "");
}
/**
* 只留下数字(0123456789)
* "dd 09".toNumber(); == ""
* onkeyup="change_number(this)"
* onafterpaste="change_number(this)"
*/
String.prototype.toNumber = function() {
return this.replace(/\D/g, "");
/**
* 删除数组指定下标或指定对象
* arr.remove(2);//删除下标为2的对象(从0开始计算)
* arr.remove(str);//删除指定对象
*/
Array.prototype.remove=function(obj){
for(var i =0;i <this.length;i++){
var temp = this[i];
if(!isNaN(obj)){
temp=i;
}
if(temp == obj){
for(var j = i;j <this.length;j++){
this[j]=this[j+1];
}
this.length = this.length-1;
}
}
}
/**
* 将时间转换成固定格式输出
* new Date().toFormat('yyyy-MM-dd HH:mm:ss');
* new Date().toFormat('yyyy/MM/dd hh:mm:ss');
* 只支持关键字(yyyy、MM、dd、HH、hh、mm、ss)HH:表示24小时,hh表示12小时
*/
Date.prototype.toFormatString=function(format){
var formatstr = format;
if(format != null && format != ""){
//设置年
if(formatstr.indexOf("yyyy") >=0 ){
formatstr = formatstr.replace("yyyy",this.getFullYear());
}
//设置月
if(formatstr.indexOf("MM") >=0 ){
var month = this.getMonth() + 1;
if(month < 10){
month = "0" + month;
}
formatstr = formatstr.replace("MM",month);
}
//设置日
if(formatstr.indexOf("dd") >=0 ){
var day = this.getDay();
if(day < 10){
day = "0" + day;
}
formatstr = formatstr.replace("dd",day);
}
//设置时 - 24小时
var hours = this.getHours();
if(formatstr.indexOf("HH") >=0 ){
if(month < 10){
month = "0" + month;
}
formatstr = formatstr.replace("HH",hours);
}
//设置时 - 12小时
if(formatstr.indexOf("hh") >=0 ){
if(hours > 12){
hours = hours - 12;
}
if(hours < 10){
hours = "0" + hours;
}
formatstr = formatstr.replace("hh",hours);
}
//设置分
if(formatstr.indexOf("mm") >=0 ){
var minute = this.getMinutes();
if(minute < 10){
minute = "0" + minute;
}
formatstr = formatstr.replace("mm",minute);
}
//设置秒
if(formatstr.indexOf("ss") >=0 ){
var second = this.getSeconds();
if(second < 10){
second = "0" + second;
}
formatstr = formatstr.replace("ss",second);
}
}
return formatstr;
}
//离开该页面时,提示!
window.onbeforeunload = function() {
if (commn.IsSearch == true) {
return "\n警告!~ \n操作正在执行中,确认需要继续?\n";
}
}
//commn对象
var commn ={
IsSearch:false,//是否正在查询数据
InputDisabled: function(eid) {//按钮点击后,按钮不可用 例如:window.setTimeout("commn.InputDisabled('#bt_submit,#bt_back')", 1);
commn.IsSearch =true;
jQuery(eid).attr("disabled","disabled");
},
DateDiffDay:function (beginDate,endDate){//获取两个时间的天数差
//beginDate、endDate 格式:2011-8-25
var arrDate = new Array();
//设置开始时间
arrDate = beginDate.split("-");
beginDate = new Date(arrDate[1] + "/" + arrDate[2] + "/" + arrDate[0]);//默认格式:8/25/2011
//设置结束时间
arrDate = endDate.split("-");
endDate = new Date(arrDate[1] + "/" + arrDate[2] + "/" + arrDate[0]);//默认格式:8/25/2011
var iDays = parseInt(Math.abs((beginDate-endDate)/1000/60/60/24));//转换天,默认毫秒
return iDays;
},
DateTimeIsFomart:function (val){//验证时分秒格式是否正确12:00:25
//判断时间位数是否正确
if(val.length == 8){
var val_r = val.replace(/\D/g,'');//只取数字
if(val_r.length == 6){//判读位置是否正确
var val_s = val.split(":");//按:分成数组
if(val_s.length == 3){//如果数组正确
var v0 = parseInt(val_s[0]);
var v1 = parseInt(val_s[1]);
var v2 = parseInt(val_s[2]);
// 当时分秒的值 处于正常范围时,返回true
if(v0 != null && (v0 >= 0 && v0 <= 23) &&
v1 != null && (v1 >= 0 && v1 <= 59) &&
v2 != null && (v2 >= 0 && v2 <= 59)
){
return true;
}
}
}
}
return false;
}
}
分享到:
相关推荐
Comm串口通信类
Comm.jar Comm.jar Comm.jar Comm.jar
(^_^)此资源是使用js调用comm32获取串口(com/LPT)数据。里面有comm32控件详细注册,附带eclipse的javaweb测试项目(项目很简单,只是测试你的控件是否注册成功!说实话,只要注册成功了,那么调用哪些方法简直简单...
WIN10平台下Prolific USB-to-Serial Comm Port线的驱动程序及安装方法。
Java常用的工具类,包含常用的一些工具类。
comm.jar,javax.comm. properties和win32comm.dll 包括存放位置说明
JavaComm部分说明
s7comm plus插件
applet读取串口必备:win32comm.dll,comm.jar,javax.comm.properties
javacomm64.zip
1.把javax.comm.properties文件拷贝到Java运行时环境的lib目录中,即: C:\Program Files\Java\jdk1.5.0_12\lib\javax.comm.properties C:\Program Files\Java\jdk1.5.0_12\jre\lib\javax.comm.properties ...
西门子PLC协议有3个版本,分别为S7Comm协议、早期S7CommPlus协议和最新的S7CommPlus协议。 S7-200、S7-300、S7-400系列的PLC采用早期的西门子私有协议S7comm通信。该协议不具备S7Comm-Plus的加密功能,不涉及任何反...
Delphi COMM SAMPLES Delphi COMM SAMPLES Delphi COMM SAMPLES
vc comm串口通信,一个串口通信的程序,还没有完善
java串口开发示例 内含win32com.dll、javax.comm.properties、comm.jar等文件 csdn上倒是资源不少,但积分要得太多了,好不容易在国外网站找到一个,免费共享给大家~~~
用java编写的一个组件,用于windows下串口通信,我已经试过了,可以成功
java串口编程包,很好用 javax.comm.properties win32com.dll comm..jar
EVE-COMM-EmulatedLab3.1.mf
javax comm properties 欢迎下载
博文链接:https://bca.iteye.com/blog/208717