App下載

bootstrap表單怎么提交信息?表單提交信息的方法有哪些?

猿友 2021-06-21 14:39:54 瀏覽數(shù) (5581)
反饋

今天小編來(lái)和大家一起學(xué)習(xí)一下有關(guān)于“bootstrap表單怎么提交信息?”這個(gè)問(wèn)題吧!對(duì)于bootstrap框架來(lái)說(shuō)學(xué)習(xí)過(guò)的小伙伴們應(yīng)該都知道這是什么,下面是有關(guān)于這個(gè)問(wèn)題小編整理的相關(guān)資料和信息,希望對(duì)大家有所幫助!


方法一:

submit提交

我們通過(guò)在前端頁(yè)面中的頭部插入一個(gè)js的方法來(lái)實(shí)現(xiàn)代碼如下:

function checkUser(){
   var result = document.getElementById("userid").value;
   var password = document.getElementById("userpassid").value;
   if(result == ""  ){
     alert("用戶名不能為空");
    return false;
   }
   if(password == ""  ){
    alert("密碼不能為空");
     return false;
   }else{
   return true;
   }
}

完成上面步驟之后我們?cè)?form?的表單中加入下面這些代碼:

<form id="formid" name="myform" method='post' action='user_login_submit.action' onsubmit="return checkUser();">

<table width="" 1O0%” border="o">

<tr>

<td width="6o" height="4o" align="right">用戶名 </td>

<td><input type="text" value="" class="text2" name="username" id="userid" />

</td>

</tr>

<tr>

<td width="6o" height="4o" align="right">密  碼 </td>

<td><input type="password" value="" class="text2" name="userpass" id="userpassid" />

</td>

</tr>

<tr>

<td width="6o" height="" 40" align="right"> </td>

<td>

<div class="c4">

<input type="submit" value="" class="btn2" />

這就是使用submit方法的相關(guān)代碼。


方法二:

button提交

對(duì)于這個(gè)方法的話我們直接看代碼:

function checkUser(){
   var result = document.getElementById("userid").value;
   var password = document.getElementById("passid").value;
   if(result == ""  ){
     alert("用戶名不能為空");
     return false;
   }
   if(password == ""  ){
    alert("密碼不能為空");
     return false;
   }
  document.getElementById("formid").submit();
}

對(duì)于?form?表格的寫(xiě)法的話我們是需要使用類選擇器的代碼如下:

<form id="formid" method = "post' action = 'user_login_submit.action'>

button按鈕的寫(xiě)法如下:

<input type="button" value="" class="btn2" onclick = "checkUser();"/>

總結(jié):

以上就是有關(guān)于“bootstrap表單怎么提交信息?”這個(gè)問(wèn)題的相關(guān)內(nèi)容,當(dāng)然如果你有更好的想法也可以提出來(lái)和大家一起分享學(xué)習(xí),更多有關(guān)于bootstrap這個(gè)框架的相關(guān)內(nèi)容我們都可以在Bootstrap教程中進(jìn)行學(xué)習(xí)和了解!


0 人點(diǎn)贊