양식 제출 유효성 검사 제출 데이터 코드
1
2 <br> // ( / )
<span style="color:#008080;"> 3</span> <span style="color:#0000ff;">function</span><span style="color:#000000;"> isNull(str){
</span><span style="color:#008080;"> 4</span> <span style="color:#0000ff;">if</span> ( str == "" ) <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 5</span> <span style="color:#0000ff;">var</span> regu = "^[ | ]+$"<span style="color:#000000;">;
</span><span style="color:#008080;"> 6</span> <span style="color:#0000ff;">var</span> re = <span style="color:#0000ff;">new</span><span style="color:#000000;"> RegExp(regu);
</span><span style="color:#008080;"> 7</span> <span style="color:#0000ff;">return</span><span style="color:#000000;"> re.test(str);
</span><span style="color:#008080;"> 8</span> <span style="color:#000000;"> }
</span><span style="color:#008080;"> 9</span>
<span style="color:#008080;">10</span> <span style="color:#0000ff;">function</span><span style="color:#000000;"> check(){
</span><span style="color:#008080;">11</span> <span style="color:#0000ff;">var</span> lname = $("#last_name"<span style="color:#000000;">);
</span><span style="color:#008080;">12</span> <span style="color:#0000ff;">if</span>(lname.val()==" " || isNull($("#last_name"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">13</span> lname.addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">14</span> <span style="color:#000000;"> lname.focus();
</span><span style="color:#008080;">15</span> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;">16</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">17</span>
<span style="color:#008080;">18</span> <span style="color:#0000ff;">if</span>($("#mobile").val()==" " || isNull($("#mobile"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">19</span> $("#mobile").addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">20</span> $("#mobile"<span style="color:#000000;">).focus();
</span><span style="color:#008080;">21</span> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;">22</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">23</span>
<span style="color:#008080;">24</span> <span style="color:#0000ff;">var</span> email = $('#email'<span style="color:#000000;">).val();
</span><span style="color:#008080;">25</span> <span style="color:#0000ff;">var</span> reg = /\w+[@]{1}\w+[.]\w+/<span style="color:#000000;">;
</span><span style="color:#008080;">26</span> <span style="color:#0000ff;">if</span><span style="color:#000000;">(reg.test(email)){
</span><span style="color:#008080;">27</span> <span style="color:#0000ff;">if</span>($('#email').hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">28</span> $('#email').removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">29</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">30</span> }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">31</span> $('#email').addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">32</span> $('#email'<span style="color:#000000;">).focus();
</span><span style="color:#008080;">33</span> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;">34</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">35</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">37</span>
<span style="color:#008080;">38</span> $(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">39</span> $('#last_name').blur(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">40</span> <span style="color:#0000ff;">if</span>($("#last_name").val()==" " || isNull($("#last_name"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">41</span> $(<span style="color:#0000ff;">this</span>).addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">42</span> }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">43</span> <span style="color:#0000ff;">if</span>($("#last_name").hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">44</span> $("#last_name").removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">45</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">46</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">47</span> <span style="color:#000000;"> });
</span><span style="color:#008080;">48</span>
<span style="color:#008080;">49</span> $('#mobile').blur(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">50</span> <span style="color:#0000ff;">if</span>($("#mobile").val()==" " || isNull($("#mobile"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">51</span> $(<span style="color:#0000ff;">this</span>).addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">52</span> }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">53</span> <span style="color:#0000ff;">if</span>($(<span style="color:#0000ff;">this</span>).hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">54</span> $(<span style="color:#0000ff;">this</span>).removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">55</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">56</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">57</span> <span style="color:#000000;"> });
</span><span style="color:#008080;">58</span>
<span style="color:#008080;">59</span> $('#email').blur(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">60</span> <span style="color:#0000ff;">var</span> email = $(<span style="color:#0000ff;">this</span><span style="color:#000000;">).val();
</span><span style="color:#008080;">61</span> <span style="color:#0000ff;">var</span> reg = /\w+[@]{1}\w+[.]\w+/<span style="color:#000000;">;
</span><span style="color:#008080;">62</span> <span style="color:#0000ff;">if</span><span style="color:#000000;">(reg.test(email)){
</span><span style="color:#008080;">63</span> <span style="color:#0000ff;">if</span>($(<span style="color:#0000ff;">this</span>).hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">64</span> $(<span style="color:#0000ff;">this</span>).removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">65</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">66</span> }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">67</span> $(<span style="color:#0000ff;">this</span>).addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">68</span> <span style="color:#000000;"> }
</span><span style="color:#008080;">69</span> <span style="color:#000000;"> });
</span><span style="color:#008080;">70</span>
<span style="color:#008080;">71</span> <span style="color:#000000;"> })
</span><span style="color:#008080;">72</span>
전재 대상:https://www.cnblogs.com/lola/p/6053733.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.