正则匹配

空白符正则匹配
whitespace = [\x20\t\r\n\f]
\xnn 由十六进制数nn指定的拉丁字符,如,\x0A等价于\n;
\uxxxx 由十六进制数xxxx指定的Unicode字符,例如\u0009等价于\t;
所以上面:
\x20 化为二进制数为 0010 0000;
ASCII码表 http://ascii.911cha.com/
字符编码笔记 http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html

正则表:

thinkphp 跨域

    public function _initialize() {
    header ( "Content-type:text/html;charset=utf-8" );
    header ( "Access-Control-Allow-Origin:*" ); // 允许任何访问(包括ajax跨域)

  }

必填选项小插件

声明

需要jq

还需要我的其他小工具
* in_array

调用

      function mustFinish_init(){

    var mustFinish_list=[
      "username",
             "password",
    ]
    MF=new mustFinish();
        //简易用法
    //MF.init("label",mustFinish_list);
        //完整用法
        MF.labels=$(".clearfix > div > label");
    MF.list=mustFinish_list;
    MF.init();

  }
    mustFinish_init();

源码

    /*===========================================必填选项*/
function mustFinish(){
  var that=this;
  this.labels=$("label");//需要标*的地方
  this.list=[];//name数组

  this.init=function(labels,list){
    that.labels=(labels)?$(labels)||that.labels:that.labels;
    that.list=list||that.list;

    //必填选项标红
    that.labels.map(function(index,element){
      var namels=$(element).parent().find("[name]");
      var isInList=false;
      namels.map(function(ind,input){
        var namevalue=input.name;
        if(in_array(namevalue,that.list)){
          isInList=true;
        }
      })
      if(isInList){
        var span=createElement("span","","*");
        span.style.color="red";
        $(element).prepend(span);
      }
    })

  }
  this.check=function(){
    var isPass=true;
    that.list.map(function(ele,ind){
      // console.dir($("[name='"+ele+"']"))
      var obj=$("[name='"+ele+"']");
      var inputValue="";
      var Nodename=obj[0].nodeName;
      var inputType;
      if(Nodename=="SELECT"){inputType="select";}
      else{inputType=obj.attr("type");}


      switch (inputType) {
        case "text":
          obj=$(obj[0]);
          inputValue=obj.val();
          break;
        case "password":
          obj=$(obj[0]);
          inputValue=obj.val();
          break;
        case "radio":
          inputValue=obj.filter(":checked").val();
          break;
        case "checkbox":
          inputValue=obj.filter(":checked").map(function(c_ind,c_ele){return c_ele.value});
          break;
        case "select":
        // console.dir(obj);
          var selecter=obj[0];
          inputValue=selecter.selectedOptions[0].value;
          inputValue=(inputValue=="请选择")?"":inputValue;
          break;
        default:
          obj=$(obj[0]);
          inputValue=obj.val();
      }
      //console.log(inputValue);
      if(!inputValue||inputValue==""){
        isPass=false;
      }
    })
    return isPass;
  }
}