遇到問題的解決方案_第1頁
遇到問題的解決方案_第2頁
遇到問題的解決方案_第3頁
遇到問題的解決方案_第4頁
遇到問題的解決方案_第5頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、1>多選框的問題(1)/科目多選框 function setsubject() var value = "" var check=document.getElementsByName("subject"); for(var i=0;i<check.length;i+) if(checki.checked) value += checki.value + "," document.getElementById("subject_values").value = value; (2) /科目必選一項 fun

2、ction check_subject() var subject = document.getElementsByName("subject"); document.getElementById("subject").innerHTML="" var value = "" for(var i=0;i<subject.length;i+) if(subjecti.checked) value += subjecti; if(value.length<=0) document.getElementById

3、("subject").innerHTML="<font color='red'>科目必選一項!</font>" return false; 2>Ajax請求(1)前臺js:Function check_name new Ajax.Request('/users/check_user_name', asynchronous:true, evalScripts:true, method:'get',parameters:"name=" + .value+&qu

4、ot;&id="+<%= user.id %>, onSuccess:function(transport) alert(transport.responseText); ); return false;(2)后臺控制器:#用戶驗證def check_user_name puts params:name user = User.find_by_name(params:name) puts user if user render :inline => "1" else render :inline => "2" e

5、ndend用<form>表單提交,加上插件 <%= javascript_include_tag :defaults %>3>action響應(yīng)<form>表單提交,使控制器響應(yīng),在控制器前頭加上 skip_before_filter :verify_authenticity_token<form>表單使ajax相應(yīng)到控制器,必須加上 <%= javascript_include_tag :defaults %>4>生成隨機數(shù)#生成隨機數(shù)(1)后臺: def get_phone_code(len=4) chars=(&quo

6、t;a"."z").to_a+("A"."Z").to_a+("0"."9").to_a get_phone_code ="" 1.upto(len)|i|get_phone_code<<charsrand(chars.size-1) get_phone_code #返回4位隨機數(shù) phone = Phone.new #新建phone表 phone.num = params:phone phone.code = get_phone_code phone.

7、save #把隨機數(shù)和電話保存phone表里 puts phone end然后在查詢phone驗證信息。(2)前臺頁面生成隨機數(shù):<pre name="code" class="js"><!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" ""> <html xmlns="" > <head> <title>無標題頁</title> <style typ

8、e="text/css"> .code background-image:url(code.jpg); font-family:Arial; font-style:italic; color:Red; border:0; padding:2px 3px; letter-spacing:3px; font-weight:bolder; .unchanged border:0; </style> <script language="javascript" type="text/javascript"> var

9、 code ; /在全局 定義驗證碼 function createCode() code = "" var codeLength = 4;/驗證碼的長度 var checkCode = document.getElementById("checkCode"); var selectChar =new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I

10、','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');/ 所有候選組成驗證碼的字符,當(dāng)然也可以用中文的 for(var i=0;i<codeLength;i+) var charIndex = Math.floor(Math.

11、random()*36); code +=selectCharcharIndex; if(checkCode) checkCode.className="code" checkCode.value = code; function validate () var inputCode = document.getElementById("input1").value; if(inputCode.length <=0) alert("請輸入驗證碼!"); else if(inputCode != code ) alert("

12、;驗證碼輸入錯誤!"); createCode();/刷新驗證碼 else alert("- OK"); </script> </head> <body onload="createCode()"> <form action="#"> <input type="text" id="input1" /> <input type="text" onclick="createCode()"

13、; readonly="readonly" id="checkCode" class="unchanged"style="width: 80px" /><br /> <input id="Button1" onclick="validate();" type="button" value="確定" /> </form> </body> </html></pre>

14、; (3)生成隨機數(shù),但在*.Html.erb中不能用<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" ""><html xmlns="" xml:lang="zh-cn" lang="zh-cn"><head><title>隨機碼</title&

15、gt;<script type="text/javascript" src=""></script><script type="text/javascript">function setVerifyImg(img, inp, focus)if(Fid(img) Fid(img).src= "?aid=15000102&"+Math.random();if(Fid(inp) && focus!=false) Fid(inp).focus();</scr

16、ipt></head><body><tr><th>&nbsp;</th><td class="col1"><img id="verifyImg" src="about:blank" alt="驗證碼" /> <a href="javascript:" class="c_3" onclick="setVerifyImg('verifyImg',

17、9;verify');return false;">換一張</a></td><td>&nbsp;</td></tr></body></html>5>各種驗證/驗證用戶名非空只能是字母、數(shù)字、下劃線組成的3-16位的正則表達式 :a-zA-Z0-9_3,16$ var name = ; if(name.value=null|name.value="") document.getElementById("name").innerHTML=

18、"<font color='red'>用戶名不能為空!</font>" name.select(); return false; /密碼非空驗證 var password = document.reg.password; var password2 = document.reg.password2; if(password.value=null|password.value="") document.getElementById("password").innerHTML="<f

19、ont color='red'>密碼不能為空!</font>" return false; /密碼長度驗證 if(password.value.length<6&&password2.value.length<6) document.getElementById("password").innerHTML="<font color='red'>密碼長度不能少于六位!</font>" return false; if(password.value

20、!= password2.value) document.getElementById("password2").innerHTML="<font color='red'>您兩次輸入的密碼不一致!</font>" return false; /姓名驗證 var user_name = er_name if(user_name.value=null|user_name.value="") document.getElementById("user_name").innerHTM

21、L="<font color='red'>姓名不能為空!</font>" return false; /昵稱驗證 var user_nich = er_nich if(user_nich.value=null|user_nich.value="") document.getElementById("user_nich").innerHTML="<font color='red'>昵稱不能為空!</font>" return false;

22、 /身份證號驗證 var user_card = er_card; if(user_card.value=null|user_card.value="") document.getElementById("user_card").innerHTML="<font color='red'>身份證號不能為空!</font>" return false; if(!(/d15$|d18$|d17x$/.test(user_card.value) document.getElementById("

23、;user_card").innerHTML="<font color='red'>請輸入15或18位!</font>" return false; /手機號驗證 var phone = document.reg.phone; if(phone.value="") document.getElementById("phone").innerHTML="<font color='red'>手機號不能為空!</font>" ret

24、urn false; var str="(130-9|150,8,3,5,6,9,1,7,2|180,9,2,7,8)d8$" var testRegExp = new RegExp(str, "gi") ; if (!testRegExp.test(phone.value) document.getElementById("phone").innerHTML="<font color='red'>手機號錯誤!</font>" phone.selet(); return fa

25、lse; /手機驗證碼驗證 var phone_check = document.reg.phone_check; if(phone_check.value=null|phone_check.value="") document.getElementById("phone_check").innerHTML="<font color='red'>手機驗證碼不能為空!</font>" return false; /密保驗證 var answer = document.reg.answer; if(

26、answer.value=null|answer.value="") document.getElementById("answer").innerHTML="<font color='red'>密保答案不能為空!</font>" return false; /QQ號碼驗證 var qq = document.reg.qq_code.value; if(!(qq ="") if(!(/1-90-94,$/.test(qq) document.getElementById(&q

27、uot;qq_code").innerHTML="<font color='red'>請輸入正確的QQ號</font>" return false; /郵箱驗證 var email = document.reg.email.value; if(!(email="") if(!(/(a-zA-Z0-9+_|_|.?)*a-zA-Z0-9+(a-zA-Z0-9+_|_|.?)*a-zA-Z0-9+.a-zA-Z2,3$/.test(email) document.getElementById("em

28、ail").innerHTML="<font color='red'>您的郵箱有誤!</font>" return false; document.getElementById("reg").submit(); 6>文件上傳必須在<% from_tag()do %>里加上 :multipart => true就行了。(而在<from>里加上enctype="MULTIPART/FORM-DATA"7>點擊按鈕,彈出一個新頁面<!DOCTY

29、PE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" ""><html xmlns=""><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Hello world</title><script type="text/javascript"&g

30、t;function check() var flag = true; if (document.getElementById("search_key").value = "找人/隨便搜" | document.getElementById("search_key").value = "") flag = false; alert("請輸入你想搜索的條件"); return false; if (document.getElementById("search_key").va

31、lue.length > 10) flag = false; alert("條件太多了,請不要超過10個字"); return false; if (flag) document.getElementById("search_form").submit(); window.open('demo.html','blank_','scrollbars=yes,resizable=yes,width=650,height=650'); /加上 blank_ 新跳轉(zhuǎn)一個新的頁面,也就是重新打開瀏覽器的一個頁面

32、;去掉 blank_ ,跳轉(zhuǎn)的新標簽頁面。</script></head><body><div class="search_sq"><form id="search_form" target="_blank" method="get" action="#"><input id="search_key" type="text" style="color: rgb(153, 153,

33、153); font-size: 14px;" onblur="if(!value)&&(value !='找人/隨便搜')value = '找人/隨便搜'this.style.color='#999'" onfocus="if(value = '找人/隨便搜')value=''this.style.color='#000'" value="找人/隨便搜" name="search_key"&g

34、t;<input id="btn" class="chaxun" type="button" onClick="check();" value="搜索"></form></div<input type="button" value="點我試試" onClick="window.open('index.html','blank_','scrollbars=yes,resiz

35、able=yes,width=650,height=650')"></html>8>sql 中排序問題 sql = "select w.* from wishes w inner join users u on u.ier_id where (u.passport like ? or u.nickname like ?) and w.status in(1,3,5) order by instr('3,5,1', w.status),w.created_at desc", "%#content%"

36、, "%#content%" if types ="1"注:模糊查詢, w.status in(1,3,5) -只查詢status1,3,5的記錄instr('3,5,1', w.status), 按status3,5,1的狀態(tài)排序9>字段截取在頁面上:<span style="color:#666" title="<%= m.contents %>"><%= truncate(h(m.contents),20,".") %></s

37、pan>在幫助類中: def truncate(text, *args) options = args.extract_options! unless args.empty? ActiveSupport:Deprecation.warn('truncate takes an option hash instead of separate ' + 'length and omission arguments', caller) options:length = args0 | 30 options:omission = args1 | ".&quo

38、t; end options.reverse_merge!(:length => 30, :omission => ".") if text l = options:length - options:omission.mb_chars.length chars = text.mb_chars (chars.length > options:length ? chars0.l + options:omission : text).to_s end end10>分頁在頁面上:<!-分頁頁面-><div class="clear"></div><%= will_paginate wishes,:renderer => "CustomPaginationRenderer" if wishes.present? %>在幫助類中:def will_p

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論