表單提交程式碼
1、原始碼分析<!DOCTYPE html><html lang=en><head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, initial-scale=1.0> <meta http-equiv=X-UA -Compatible content=ie=edge> <title>Document</title></head><body><form action=/form.html method=GET> <!-- action: 表單提交的地址--> <!-- method:提交保單的方法--><div class=name> <label for=name>使用者名稱</label> <input type=text name=name id=name placeholder=請輸入使用者名稱> <!-- placeholder是透明的提示文字--></div><div class=password> <label for=password>密碼</label> <input type=password name=password id=password placeholder=請輸入密碼></div><div class=sex> <label for=sex>性別</label> <input type=radio name=sex value=male>男<input type=radio name=sex value=female>女</div><div class=city> <label for=city>最喜歡的城市</label> <select name=city id=city> <option value=beijing>北京</option> <option value=shanghai>上海</option> <option value=chongqing selected >重慶</option> <!-- selected 表示被選取在頁面展示的選項--> </select></div><div class=hobby> <label for=hobby>嗜好</label> <input type=checkbox name=hobby value=read>閱讀<input type=checkbox name=hobby value=flower>插花<input type=checkbox name=hobby value=sing>唱歌<! -- 所有選項name要一樣--></div><div class=area> <textarea id=area name=area cols=30 rows=10></textarea></div><button>button</button><!-- 可以提交表單--><input type=submit value=submit> <!-- 可以提交表單-->< input type=button value=button><!-- 不可以提交表單--><input type=reset value=reset><!--將表單裡面已經輸入的內容做重置--></form></body></html>2、終端操作
開啟終端gitbash,切換到html所在的資料夾
用命令列http-server開啟靜態伺服器,開啟後會出現兩個ip位址。 127.xxx是本地存取位址,125.xxx是區域網路存取位址(這裡的前提是已經安裝了nodejs,並用npm安裝了http-server這個伺服器)
用瀏覽器開啟html檔案。用http://127.0.0.1:8080,取代本地的file檔案位址。
點開檢查-network-header可以看到表單提交的信息
3.get和post方式區別所有input標籤要加上name屬性,不然該資料不能正確接收。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。