//正则检验
function check_reg(reg,str) {
if(reg.test(str)){
return true;
}
else {
return false;
}
}
//去除前后空格
String.prototype.trim = function () {
return this.replace(/(^\s*)|(\s*$)/g,'')
};
//去除左边空格
String.prototype.ltrim = function () {
return this.replace(/^\s*/g,'')
};
//去除右边空格
String.prototype.rtrim = function () {
return this.replace(/\s*$/g,'')
};
//js 的String有去空格的方法
a.trim()
a.trimLeft()
a.trimRight()
//获取XMLHttpRequest 对象
function xmlhttpRequest(){
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp
}
//ajax封装函数,xmlhttp:XMLHttpRequest 对象,func:处理响应的函数,url:请求的地址,method:请求方式,param:请求参数
function myajax(xmlhttp,func,url,method="GET",param="") {
xmlhttp.onreadystatechange = func;
xmlhttp.open(method,url,true);
if (method == "POST"){
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
}
xmlhttp.send(param);
}
常用js
最新推荐文章于 2025-06-05 16:12:57 发布