實踐中的importPoint

1.focus()
是HTML DOM對象的方法,並不是js的函數,js只是調用對象的focus方法.
該方法表示將輸入焦點移至對象上.
<script type="text/javascript">        
    function validatefield(field)
        {
            if (field.value == "") {
                alert("不能爲空內,謝謝");
                field.focus();
                return false;
            }
            else
            {
                name = field.value;
                alert(name+",hello")
            }
 
            return true;        }
</script>

 

2.javacsript中window.open()與window.location.href的區別

window.open("index.aspx",'top'); 只是表示打開這個頁面,並不是打開並刷新index.aspx
window.location.href="index.aspx"; 表示重新定向到新頁面,同時刷新打開的這個頁面;
eg:
<tr><td 
style="width:96%;">進行中項目</td><td><img alt="" 
src="Images/2emorewe.gif" style="text-align:right;cursor:hand;"
onclick="javascript:window.open('ProjectList.aspx?flag=0','_top');"/></td></tr>  
 
<tr><td 
style="width:96%;">進行中項目</td><td><img alt="" 
src="Images/2emorewe.gif" style="text-align:right;cursor:hand;" 
onclick="javascript:window.location.href='ProjectList.aspx?flag=0';"/></td></tr>
這兩個的效果不同

javascript中的location.href有很多種用法,主要如下。

self.location.href="/url" 當前頁面打開URL頁面
location.href="/url" 當前頁面打開URL頁面
windows.location.href="/url" 當前頁面打開URL頁面,前面三個用法相同。
this.location.href="/url" 當前頁面打開URL頁面
parent.location.href="/url" 在父頁面打開新頁面
top.location.href="/url" 在頂層頁面打開新頁面

如果頁面中自定義了frame,那麼可將parent self top換爲自定義frame的名稱,效果是在frame窗口打開url地址

此外,window.location.href=window.location.href;和 window.location.Reload()和都是刷新當前頁面。區別在於是否有提交數據。當有提交數據 時,window.location.Reload()會提示是否提 交,window.location.href=window.location.href;則是向指定的url提交數據
   
 
3.
history.back() 
功能:加載歷史列表中的前一個URL(後退)。 

語法:history.back() 

調用該方法的效果等價於點擊後退按鈕或調用history.go(-1)。 

history.forward() 
功能:加載歷史列表中的下一個URL(前進)。 

語法:history.forward() 

調用該方法的效果等價於點擊前進按鈕或調用history.go(1)。 

history.go() 
功能:加載歷史列表中的某個具體的頁面。 

語法:history.go(number) 

參數: 
number:要訪問的URL在History的URL列表中的相對位置. 

-1代表前一個(forward),0代表當前,1代表(back)後一個。 

1(向後) <----- 0(當前) -----> -1(向前) 
history.go(-1) == history.forward() 
history.go(1)  == history.back() 
history.current, history.next


 

    


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章