{"id":514,"date":"2017-02-05T10:24:30","date_gmt":"2017-02-05T02:24:30","guid":{"rendered":"http:\/\/loveuhouse.cn\/wordpress\/?p=514"},"modified":"2017-02-05T10:36:32","modified_gmt":"2017-02-05T02:36:32","slug":"%e5%bf%85%e5%a1%ab%e9%80%89%e9%a1%b9%e5%b0%8f%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/loveuhouse.cn\/wordpress\/?p=514","title":{"rendered":"\u5fc5\u586b\u9009\u9879\u5c0f\u63d2\u4ef6"},"content":{"rendered":"<blockquote><p>\n  \u58f0\u660e\n<\/p><\/blockquote>\n<h3>\u9700\u8981jq<\/h3>\n<p>\u8fd8\u9700\u8981\u6211\u7684\u5176\u4ed6\u5c0f\u5de5\u5177<br \/>\n* in_array<\/p>\n<blockquote><p>\n  \u8c03\u7528\n<\/p><\/blockquote>\n<pre class=\"lang:js decode:true\">\n      function mustFinish_init(){\n\n    var mustFinish_list=[\n      \"username\",\n             \"password\",\n    ]\n    MF=new mustFinish();\n        \/\/\u7b80\u6613\u7528\u6cd5\n    \/\/MF.init(\"label\",mustFinish_list);\n        \/\/\u5b8c\u6574\u7528\u6cd5\n        MF.labels=$(\".clearfix > div > label\");\n    MF.list=mustFinish_list;\n    MF.init();\n\n  }\n    mustFinish_init();\n<\/pre>\n<blockquote><p>\n  \u6e90\u7801\n<\/p><\/blockquote>\n<pre class=\"lang:js decode:true\">\n    \/*===========================================\u5fc5\u586b\u9009\u9879*\/\nfunction mustFinish(){\n  var that=this;\n  this.labels=$(\"label\");\/\/\u9700\u8981\u6807*\u7684\u5730\u65b9\n  this.list=[];\/\/name\u6570\u7ec4\n\n  this.init=function(labels,list){\n    that.labels=(labels)?$(labels)||that.labels:that.labels;\n    that.list=list||that.list;\n\n    \/\/\u5fc5\u586b\u9009\u9879\u6807\u7ea2\n    that.labels.map(function(index,element){\n      var namels=$(element).parent().find(\"[name]\");\n      var isInList=false;\n      namels.map(function(ind,input){\n        var namevalue=input.name;\n        if(in_array(namevalue,that.list)){\n          isInList=true;\n        }\n      })\n      if(isInList){\n        var span=createElement(\"span\",\"\",\"*\");\n        span.style.color=\"red\";\n        $(element).prepend(span);\n      }\n    })\n\n  }\n  this.check=function(){\n    var isPass=true;\n    that.list.map(function(ele,ind){\n      \/\/ console.dir($(\"[name='\"+ele+\"']\"))\n      var obj=$(\"[name='\"+ele+\"']\");\n      var inputValue=\"\";\n      var Nodename=obj[0].nodeName;\n      var inputType;\n      if(Nodename==\"SELECT\"){inputType=\"select\";}\n      else{inputType=obj.attr(\"type\");}\n\n\n      switch (inputType) {\n        case \"text\":\n          obj=$(obj[0]);\n          inputValue=obj.val();\n          break;\n        case \"password\":\n          obj=$(obj[0]);\n          inputValue=obj.val();\n          break;\n        case \"radio\":\n          inputValue=obj.filter(\":checked\").val();\n          break;\n        case \"checkbox\":\n          inputValue=obj.filter(\":checked\").map(function(c_ind,c_ele){return c_ele.value});\n          break;\n        case \"select\":\n        \/\/ console.dir(obj);\n          var selecter=obj[0];\n          inputValue=selecter.selectedOptions[0].value;\n          inputValue=(inputValue==\"\u8bf7\u9009\u62e9\")?\"\":inputValue;\n          break;\n        default:\n          obj=$(obj[0]);\n          inputValue=obj.val();\n      }\n      \/\/console.log(inputValue);\n      if(!inputValue||inputValue==\"\"){\n        isPass=false;\n      }\n    })\n    return isPass;\n  }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u58f0\u660e \u9700\u8981jq \u8fd8\u9700\u8981\u6211\u7684\u5176\u4ed6\u5c0f\u5de5\u5177 * in_array \u8c03\u7528 function mustFinish_in &hellip; <a href=\"https:\/\/loveuhouse.cn\/wordpress\/?p=514\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u5fc5\u586b\u9009\u9879\u5c0f\u63d2\u4ef6<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"_links":{"self":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/514"}],"collection":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=514"}],"version-history":[{"count":2,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/514\/revisions"}],"predecessor-version":[{"id":516,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/514\/revisions\/516"}],"wp:attachment":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}