{"rsdb":{"rid":"352099","subhead":"","postdate":"0","aid":"249904","fid":"100","uid":"1","topic":"1","content":"
\n

    \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u8868\u5355\u9a8c\u8bc1\u524d\u9762\u7684\u4e24\u7bc7\u6587\u7ae0\u505a\u7684\u6548\u679c\u603b\u611f\u89c9\u90fd\u6709\u70b9\u4e0d\u592a\u53cb\u597d\uff0c\u7b2c\u4e00\u7bc7\u91cc\u7684\u6548\u679c\u662f\u5c06\u9519\u8bef\u4fe1\u606f\u901a\u8fc7\u5bf9\u8bdd\u6846\u5f62\u5f0f\u5f39\u51fa\u6765\uff0c\u8fd9\u79cd\u5f62\u5f0f\u5728web\u5f62\u5f0f\u4e0b\u65e9\u5df2\u7ecf\u6dd8\u6c70\u4e86\uff1b\u7b2c\u4e8c\u7bc7\u662f\u4e00\u6b21\u6027\u5168\u90e8\u663e\u793a\u6240\u6709\u7684\u9519\u8bef\uff0c\u7136\u540e3\u79d2\u540e\u81ea\u52a8\u6d88\u5931\uff0c<\/p> \n

\u8fd9\u79cd\u5728\u6781\u7aef\u60c5\u51b5\u4e0b\u4e5f\u4e0d\u592a\u597d\uff0c\u4f8b\u5982\u6211\u4f8b\u5b50\u91cc\u7684\u4e00\u9875\u7684\u8868\u5355\u4e2a\u6570\u975e\u5e38\u591a\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u540e\u9762\u7684\u8fd8\u6ca1\u770b\u5230\u5c31\u6d88\u5931\u4e86\u3002\u6240\u4ee5\u6700\u8fd1\u53c8\u91cd\u65b0\u505a\u4e86\u4e00\u7248\uff0c\u6700\u7ec8\u7248\u7684\u6548\u679c\u5982\u4e0b\u56fe\uff1a\u9519\u8bef\u4fe1\u606f\u4e00\u6b21\u6027\u5168\u90e8\u663e\u793a\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u4fe1\u606f\u6846\u8ba9\u5176\u6d88\u5931\uff0c\u5c06\u81ea\u52a8\u6d88\u5931\u65f6\u95f4\u8bbe\u7f6e\u7684\u7a0d\u5fae\u957f\u70b9\uff0c\u4f8b\u598210\u79d2\uff0c\u8fd9\u6837\u5c31\u80fd\u6bd4\u8f83\u597d\u7684\u517c\u987e\u6548\u679c\u548c\u4f7f\u7528\u4e0a\u7684\u4fbf\u6377\u3002<\/p> \n

\"\"<\/p> \n

\u5148\u8bb2\u8bb2\u6700\u7ec8\u7248\u4e0e\u524d\u97622\u7248\u7684\u4e0d\u540c\u70b9<\/p> \n

1.\u524d\u9762\u7248\u672c\u4e2d\u63d0\u5230\uff0c\u8868\u5355\u63a7\u4ef6\u91cc\u9700\u8981\u6dfb\u52a03\u4e2a\u53c2\u6570\uff1aid,data-fieldname,data-validate \u3002\u6700\u7ec8\u7248\u4e2d\u53ea\u9700\u8981 data-validate \u5373\u53ef\u3002<\/p> \n

2.\u7531\u4e8e\u9700\u8981\u70b9\u51fb\u9519\u8bef\u4fe1\u606f\u6846\u540e\u4f7f\u5176\u9690\u85cf\uff0c\u5219\u9700\u8981\u901a\u8fc7\u5fae\u4fe1\u5c0f\u7a0b\u5e8fwxs\u4e8b\u4ef6\u54cd\u5e94\u529f\u80fd\uff0c\u65b0\u589e\u4e8b\u4ef6<\/p> \n

 <\/p> \n

\u4e00\u3001util.wxs\u6587\u4ef6<\/p> \n

\n
module.exports = {\r\n  hiddenValidateError: hiddenValidateError\r\n}\r\n<\/span>function<\/span> hiddenValidateError(event, ownerInstance) {\r\n  <\/span>var<\/span> index= event.target.dataset.index;\r\n  <\/span>var<\/span> instance = ownerInstance.selectComponent('.validateText'+index) \/\/<\/span> \u8fd4\u56de\u7ec4\u4ef6\u7684\u5b9e\u4f8b<\/span>\r\n  instance.setStyle({\r\n    <\/span>"visibility": "hidden"\r\n  }) \r\n}<\/span><\/pre> \n <\/div> \n 

 <\/p> \n

\u4e8c\u3001wxml\u6587\u4ef6<\/p> \n

\n
<wxs module="wxs" src="..\/..\/utils\/util.wxs"><\/wxs>\r\n<block wx:for<\/span>="{{arrValidate}}" wx:for<\/span>-item="validateErrorText">\r\n  <view class="validateText validateText{{validateErrorText.index}}" animation="{{vaildateErrorText_animation}}" style="visibility:{{validateErrorText.visibility}};top:{{validateErrorText.top}};left:{{validateErrorText.left}};" data-index="{{validateErrorText.index}}" bindtap="{{wxs.hiddenValidateError}}">\r\n    {{validateErrorText.msg}}\r\n  <\/span><\/view>\r\n<\/block><\/pre> \n  
\n
\n <form bindsubmit="formSubmit">\n <\/div> \n
\n <view class="wide-info">\n <\/div> \n
\n <view class="wide-info-list">\n <\/div> \n
\n <!--\u59d3\u540d-->\n <\/div> \n
\n <view class="info-list">\n <\/div> \n
\n <view class="info-list-1eft">\n <\/div> \n
\n <text class="notEmptyClass">\u59d3\u540d<\/text>\n <\/div> \n
\n <\/view>\n <\/div> \n
\n <view class="info-list-right">\n <\/div> \n
\n <input name='tname' placeholder='\u8bf7\u8f93\u5165' value='{{form.tname}}' class="wxValidate inputName"\n <\/div> \n
\n data-validate="notEmpty|size[4,10]"\/>\n <\/div> \n
\n <\/view>\n <\/div> \n
\n <\/view>\n <\/div> \n
\n ......\n <\/div> \n
\n
\n
\n <\/view>\n <\/div> \n
\n <!--\u6309\u94ae--->\n <\/div> \n
\n <view class="buttons-kind">\n <\/div> \n
\n <button class="fabu" form-type="submit">\u53d1\u5e03<\/button>\n <\/div> \n
\n <\/view>\n <\/div> \n
\n <\/form>\n <\/div> \n <\/div> \n <\/div> \n <\/div> \n <\/div> \n

 <\/p> \n

\u4e09\u3001form.js <\/p> \n

\n
onReady: function<\/span> () {\r\n    <\/span>\/\/<\/span>\u9a8c\u8bc1\u65b9\u6cd5<\/span>\r\n    this<\/span>.WxValidate = new<\/span> WxValidate();\r\n},\r\nformSubmit: <\/span>function<\/span> (e) {\r\n    util.loadingMsg(<\/span>"\u6570\u636e\u63d0\u4ea4\u4e2d\uff0c\u8bf7\u7a0d\u540e...");\r\n    <\/span>var<\/span> that = this<\/span>;\r\n    console.log(<\/span>'form\u53d1\u751f\u4e86submit\u4e8b\u4ef6\uff0c\u643a\u5e26\u7684\u6570\u636e\u4e3a\uff1a', e.detail.value)\r\n    const params <\/span>= e.detail.value    \r\n    <\/span>\/\/<\/span>\u6821\u9a8c\u8868\u5355<\/span>\r\n    if<\/span> (!this<\/span>.WxValidate.checkForm(params)) {\r\n      <\/span>var<\/span> arrValidate = new<\/span> Array();\r\n      let top <\/span>= 0;\r\n      <\/span>for<\/span> (const i in<\/span> this<\/span>.WxValidate.errorList){\r\n        const error <\/span>= this<\/span>.WxValidate.errorList[i]\r\n        <\/span>if<\/span>(i==0){          \r\n          top <\/span>= error.top;\r\n        }       \r\n        const validateErrorText<\/span>= {id:error.param, visibility: "inherit", top: error.top + "px", left: error.left + "px", msg: error.msg }        \r\n        arrValidate[i]<\/span>=validateErrorText;\r\n      }\r\n      <\/span>this<\/span>.setData({arrValidate: arrValidate});\r\n\r\n)\r\n      wx.pageScrollTo({\r\n        scrollTop: top,\r\n        duration:<\/span>500\r\n      });\r\n      setTimeout(<\/span>function<\/span>(){              \r\n        util.fadeOut(that, <\/span>"vaildateErrorText_animation", 0);\r\n      },<\/span>10000);\r\n      wx.hideLoading();   \r\n      <\/span>return<\/span> false<\/span>\r\n    } \r\n    wx.hideLoading();\r\n    <\/span>\/\/<\/span>\u5411\u540e\u53f0\u53d1\u9001\u65f6\u6570\u636e wx.requ","orderid":"0","title":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u2014\u2014\u8868\u5355\u9a8c\u8bc1\u63d2\u4ef6WxValidate\u7684\u4e8c\u6b21\u5c01\u88c5\uff08\u7ec8\u6781\u7248\uff09(\u4e00)","smalltitle":"","mid":"0","fname":"\u5176\u5b83","special_id":"0","bak_id":"0","info":"0","hits":"44","pages":"2","comments":"0","posttime":"2019-09-04 00:55:51","list":"1567529751","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u7a0b\u5e8f<\/A> \u8868\u5355<\/A> \u9a8c\u8bc1<\/A> \u63d2\u4ef6<\/A> WxValidate<\/A> \u5c01\u88c5<\/A> \u7ec8\u6781<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"120.229.33.222","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u2014\u2014\u8868\u5355\u9a8c\u8bc1\u63d2\u4ef6WxValidate\u7684\u4e8c\u6b21\u5c01\u88c5\uff08\u7ec8\u6781\u7248\uff09","lastview":"1575478659","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}