Posted on 2006-09-05 21:42
sugo 閱讀(150)
評論(0) 編輯 收藏
1、當在一個文本框輸入內容時,下一個文本框自動填寫上一個文本框輸入的內容。簡單代碼如下:
????? <form name="fm" >
???????<input name="first" onpropertychange="fm.second.value=fm.first.value">
???????<input name="second">
????? </form>
2、enter鍵代替tab鍵。在控件的onkeydown事件中使用簡單的一行代碼即可:
????? if (window.event.keyCode==13) window.event.keyCode=9
3、強迫用戶讀取注冊協議的計時按鈕。主要是使用window.setTimeout()這個方法:
??????? var secs = 180;
??????? document.agree.agreeb.disabled=true;
??????? for(i=1;i<=secs;i++)
?????? {
????????????? window.setTimeout("update(" + i + ")",i*1000);//這里的計時嚴格來說不是很準確
???????? }
???????? function update(num) {
?????????? if(num == secs) {
????????????? document.agree.agreeb.value ="同意";
????????????? document.agree.agreeb.disabled=false;
???????? }
??????? else {
??????????? printnr = secs-num;
?????????? document.agree.agreeb.value = "請認真閱讀協議(" + printnr +" 后才能繼續注冊)";
???? }
4、文本框和file控件一起提交
????? 如果還是像原來的表單提交一樣,此操作是不可行的。什么原因不太清楚,錯誤提示好像是語法方面的錯誤。解決方法就得靠javascript了。另外就是提交按鈕換成一般的button,通過button調用一個函數,最后通過表單名.submit()方法來提交。代碼簡單如下:
????? <form? method="post" name="fm">
???????? <input name="picname">
???????? <input type="file" name="pic">
???????? <input type="button" onclick="go()">
???? </form>
???? function go(){
???? var? picturename=fm.picname.value;
???? var? filename=fm.pic.value;
???? fm.action="test.jsp?pname="+picturename+"&fname="+filename;
???? fm.submit();
??? }
?5、兩個html頁面傳遞參數
?????? 使用js來接受 通過一個location.search就可以獲得后面的參數值
???? (to be continued)