程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> ASP常用函數:CheckBoxScript()

ASP常用函數:CheckBoxScript()

編輯:ASP技巧

程序代碼
<%
'功能:用來在指定CheckBox的哪幾個值上打勾
'來源:http://www.knowsky.com/asp.ASP

Function CheckBoxScript(ByVal FormElement , ByVal ElementValue)
    CheckBoxScript = "<scr" & "ipt language=""Javascript"" type=""text/Javascript"">" & vbCrLf & "String.PRototype."
    CheckBoxScript = CheckBoxScript & "ReallyDo=function(){return this.replace(/(^\s*)|(\s*$)/g,"""");}" & vbCrLf
    CheckBoxScript = CheckBoxScript & "var Jorkin = """ & ElementValue & """.split("","");" & vbCrLf
    CheckBoxScript = CheckBoxScript & "for (i = 0; i < " & FormElement & ".length; i++){" & vbCrLf
    CheckBoxScript = CheckBoxScript & "  for (j = 0; j < Jorkin.length; j++){" & vbCrLf
    CheckBoxScript = CheckBoxScript & "    if (Jorkin[j].ReallyDo() == " & FormElement & "[i].value.ReallyDo()){" & vbCrLf
    CheckBoxScript = CheckBoxScript & "      " & FormElement & "[i].checked = true } } }</scr" & "ipt>" & vbCrLf
End Function
%>

例子:

 程序代碼
<form name="Form1">
<input name="ReallyDo" type="checkbox" id="ReallyDo1" value="10" />10
<input name="ReallyDo" type="checkbox" id="ReallyDo2" value="20" />20
<input name="ReallyDo" type="checkbox" id="ReallyDo3" value="30" />30
<input name="ReallyDo" type="checkbox" id="ReallyDo4" value="40" />40
<input name="ReallyDo" type="checkbox" id="ReallyDo5" value="50" />50
</form>
<%=CheckBoxScript("Form1.ReallyDo","10,30, 50")%>

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved