整理

      Javascript 2005-7-27 22:18
1、下拉框有三个选项,值分别为:01,02,03
利用ASP得到数据库里的值为02..通JS来设置下拉框的当前项为02.
<select id="oSelect" name="oSelect">
<option value="01" <% If rs("column")="01" Then Response.Write " selected" %>>01</option>
<option value="02" <% If rs("column")="02" Then Response.Write " selected" %>>02</option>
<option value="03" <% If rs("column")="03" Then Response.Write " selected" %>>03</option>
</select>
2、frameset一个框架中更新另一框架的语句:
response.Write("<script>")
response.Write("parent.frames[1].location.href('left.asp');")
response.Write("</script>")
3、网站注册时阅读声明的倒计时
<SCRIPT>
secs = 60; // Number of secs to delay -CHINA-studio
wait = secs * 100;
document.forms.register.Submit.disabled =true;
for(i=1;i<=(wait/100);i++) {
window.setTimeout("doUpdate(" + i + ")", i * 100);
}
window.setTimeout("Timer()", wait);

function doUpdate(num) {
if(num == (wait/100)) {
document.forms.register.Submit.value = " 同意注册 ";
} else {
wut = (wait/100)-num;
document.forms.register.Submit.value = " 同意前请先阅读 (" + wut + ")";
}
}

function Timer() {
document.forms.register.Submit.disabled =false;
}
</SCRIPT>
4、得到真实IP
得到IP地址的方法是<%=Request.ServerVariables("REMOTE_ADDR")%>,如果客户使用的代理服务器,这样就得到了代理服务器的IP,下面是得到真实IP的代码:
function GetIp()
dim realip,proxy
realip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
proxy = Request.ServerVariables("REMOTE_ADDR")
if realip = "" then
GetIp = proxy
else
GetIp = realip
end if
end function
5、<script language="javascript">
<!--
function locationURL()
{
window.location="do_select.asp";
}
//-->
</script>
<input type="radio" name="radiobutton" value="radiobutton" onClick="locationURL()">
5、javascript中截去空字符串,相当于vbscript中的trim().
function trim(s){
if (s == null)
{
return s;
}
var i;
var beginIndex = 0;
var endIndex = s.length - 1;
for (i=0; i<s.length; i++)
{
if (s.charAt(i)==' '||s.charAt(i)==' ')
{
beginIndex++;
}
else
{
break;
}
}
for (i = s.length - 1; i >= 0; i--)
{
if (s.charAt(i) == ' ' || s.charAt(i) == ' ')
{
endIndex--;
}
else
{
break;
}
}
if (endIndex < beginIndex)
{
return "";
}
return s.substring(beginIndex, endIndex + 1);
}
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}