9章 表單[js] —— javaScript寶典

來源:互聯網
上載者:User

9.1 form對象

form對象

document.forms[0]

使用元素名稱的字串作為數組下標

document.forms[“formName”]

注意:數組引用單詞的複數形式

另外可以使用表單名 document.formName

9.1訪問表單屬性

document.forms[0].action = ”http://www.howia.net” ;  //改變屬性直接賦值

document.formName.target

 

9.2作為對象的表單控制項

例如

<form name="searchForm"><input type="text" name="entry"><input type="submit" name="sender" value="Serach"></form>

對文本輸入控制項以下都有效

document.searchForm.entrydocument.searchForm.elements[0]document.forms["searchForm"].elements["entry"]document.forms["searchForm"].entry

9.2.2按鈕對象

9.2.3複選框對象

9.2.4單選框對象

讀取組的按鈕數

document.forms[0].groupName.length

想查詢某個按鈕是否高亮顯示【check屬性】

document.forms[0].groupName.checked

9.2.5 Select對象

select最重要屬性selectedIndex

selectedIndex 屬性可設定或返回下拉式清單中被選選項的索引號

document.forms[0].selectName.selectedIndex

其中2個重要屬性text和value

doucument.forms[0].selectName.options[n].text

doucument.forms[0].selectName.options[n].value

function goThere(){    var list=document.forms[0].urlList;    location.href=list.options[list.selectedIndex].value;}

9.3向函數傳遞表單資料和元素

(1) onchange="upperMe(this)"

接收端,函數定義一個參數變數將引用轉換為變數,這個變數可以被函數的其他語句使用

finction upperMe(filed){

statment[s]

}

(2)可以使用this關鍵字來引用當前控制項,再加上form屬性,如this.form

onclick="inspact(this.form)"

函數定義應該有一個參數變數被賦值為form對象引用,使用者可以確定變數名或不用變數名,我們傾向於使用form變數名,以提醒使用者所引用變數

function inspact(form){

statment[s]

}

9.4提交和預驗證表單

document.forms[0].submit();

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.