js擷取表單資料

來源:互聯網
上載者:User

標籤:js   jsp   表單   資料   null   

曾經嘗試了很多方法,網上也推薦了好多方法。一般都是:document.getElementById(‘mail‘).value

但是我嘗試了好多次,返回值都是空

最後找到一個方法比較可行,而且擷取表單的所有input都很方便:

document.JSRegistForm.RegistUsername.value

下面列出我的原始碼:

<form action="zhuce.jsp" method="post" name="JSRegistForm" id="JSRegistForm" enctype="multipart/form-data" onsubmit="return Check_string_length()">
    <p> 
    <lable>使用者名稱&nbsp;&nbsp;<font color="red">*</font></lable><input type="text" name="RegistUsername" id="RegistUsername"/>
    </p>

<p>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="tj" value="註冊" />
    </p>

一下是js代碼:

function Check_string_length(){
//當js語法錯誤時,很可能是js文法有問題
var jsusername=document.JSRegistForm.RegistUsername.value;
//var username_length=jsusername.length();
alert("訊息來自js檔案"+jsusername);
return false;

}

js擷取表單資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.