




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1多选框的问题(1)/科目多选框 function setsubject() var value = ; var check=document.getElementsByName(subject); for(var i=0;icheck.length;i+) if(checki.checked) value += checki.value + ,; document.getElementById(subject_values).value = value; (2) /科目必选一项 function check_subject() var subject = document.getElementsByName(subject); document.getElementById(subject).innerHTML=; var value = ; for(var i=0;isubject.length;i+) if(subjecti.checked) value += subjecti; if(value.length=0) document.getElementById(subject).innerHTML=科目必选一项! return false; 2Ajax请求(1)前台js:Function check_name new Ajax.Request(/users/check_user_name, asynchronous:true, evalScripts:true, method:get,parameters:name= + .value+&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 endend用表单提交,加上插件 3action响应表单提交,使控制器响应,在控制器前头加上 skip_before_filter :verify_authenticity_token表单使ajax相应到控制器,必须加上 4生成随机数#生成随机数(1)后台: def get_phone_code(len=4) chars=(a.z).to_a+(A.Z).to_a+(0.9).to_a get_phone_code = 1.upto(len)|i|get_phone_codecharsrand(chars.size-1) get_phone_code #返回4位随机数 phone = Phone.new #新建phone表 phone.num = params:phone phone.code = get_phone_code phone.save #把随机数和电话保存phone表里 puts phone end然后在查询phone验证信息。(2)前台页面生成随机数: 无标题页 .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; var 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,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);/ 所有候选组成验证码的字符,当然也可以用中文的 for(var i=0;icodeLength;i+) var charIndex = Math.floor(Math.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(验证码输入错误!); createCode();/刷新验证码 else alert(- OK); (3)生成随机数,但在*.Html.erb中不能用随机码function setVerifyImg(img, inp, focus)if(Fid(img) Fid(img).src= /getimage?aid=15000102&+Math.random();if(Fid(inp) & focus!=false) Fid(inp).focus(); 换一张 5各种验证/验证用户名非空只能是字母、数字、下划线组成的3-16位的正则表达式 :a-zA-Z0-9_3,16$ var name = ; if(name.value=null|name.value=) document.getElementById(name).innerHTML=用户名不能为空!; name.select(); return false; /密码非空验证 var password = document.reg.password; var password2 = document.reg.password2; if(password.value=null|password.value=) document.getElementById(password).innerHTML=密码不能为空! return false; /密码长度验证 if(password.value.length6&password2.value.length6) document.getElementById(password).innerHTML=密码长度不能少于六位! return false; if(password.value!= password2.value) document.getElementById(password2).innerHTML=您两次输入的密码不一致! return false; /姓名验证 var user_name = document.reg.user_name if(user_name.value=null|user_name.value=) document.getElementById(user_name).innerHTML=姓名不能为空! return false; /昵称验证 var user_nich = document.reg.user_nich if(user_nich.value=null|user_nich.value=) document.getElementById(user_nich).innerHTML=昵称不能为空! return false; /身份证号验证 var user_card = document.reg.user_card; if(user_card.value=null|user_card.value=) document.getElementById(user_card).innerHTML=身份证号不能为空! return false; if(!(/d15$|d18$|d17x$/.test(user_card.value) document.getElementById(user_card).innerHTML=请输入15或18位! return false; /手机号验证 var phone = document.reg.phone; if(phone.value=) document.getElementById(phone).innerHTML=手机号不能为空! return 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=手机号错误!; phone.selet(); return false; /手机验证码验证 var phone_check = document.reg.phone_check; if(phone_check.value=null|phone_check.value=) document.getElementById(phone_check).innerHTML=手机验证码不能为空! return false; /密保验证 var answer = document.reg.answer; if(answer.value=null|answer.value=) document.getElementById(answer).innerHTML=密保答案不能为空! return false; /QQ号码验证 var qq = document.reg.qq_code.value; if(!(qq =) if(!(/1-90-94,$/.test(qq) document.getElementById(qq_code).innerHTML=请输入正确的QQ号; 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(email).innerHTML=您的邮箱有误! return false; document.getElementById(reg).submit(); 6文件上传必须在里加上 :multipart = true就行了。(而在里加上enctype=MULTIPART/FORM-DATA7点击按钮,弹出一个新页面Hello worldfunction 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).value.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_ 新跳转一个新的页面,也就是重新打开浏览器的一个页面;去掉 blank_ ,跳转的新标签页面。/div8sql 中排序问题 sql = select w.* from wishes w inner join users u on u.id=w.user_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%, %#content% if types =1注:模糊查询, w.status in(1,3,5) -只查询status1,3,5的记录instr(3,5,1, w.status), 按status3,5,1的状态排序9字段截取在页面上:span style=color:#666 title=在帮助类中: 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 | . 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分页在页面上: CustomPaginationRenderer if wishes.present? %在帮助类中:def will_paginate(collection = nil, options = ) options, collection = collection, nil if collection.is_a? Hash unless collection or !controller collection_name = #controller.controller_name collection = instance_variable_get(collection_name) raise ArgumentError, The #collection_name variable appears to be empty. Did you + forget to pass the collection object for will_paginate? unless collection end # early exit if there is nothing to render return nil unless WillPaginate:ViewHe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公司茶艺活动策划方案
- 公司春节游园活动方案
- 公司聚会创意活动方案
- 公司无人文关怀活动方案
- 公司端午宣传活动方案
- 公司舞会活动方案
- 公司春节留守活动方案
- 公司景区活动策划方案
- 公司热极年会活动方案
- 公司知识闯关活动方案
- 2025春统编版小学道德与法治五年级下册(全册)教案、教学反思、教学计划(附教材目录P141)
- 高血压病人个体化健康教育方案
- 脑挫伤患者的护理
- 腰椎间盘突出症手术的围手术期护理
- 警卫道路培训课件
- 感染性疾病分子诊断试剂行业深度调研及发展战略咨询报告
- GB/T 45355-2025无压埋地排污、排水用聚乙烯(PE)管道系统
- 安全生产风险防控课件
- ISO45001 2024职业健康安全管理体系要求及使用指南
- 2025年湖南株洲南方中学自主招生英语试卷真题(含答案详解)
- 劳务绿化合同范本
评论
0/150
提交评论