1. 程式人生 > >jQuery的ajax表單提交,獲取元素內容方法

jQuery的ajax表單提交,獲取元素內容方法

jQuery的ajax表單提交

  • .val() 獲取指定元素的value值,通常指表單元素
  • .html() 獲得指定的html元素以及文字
  • .text() 獲得當前元素表現的文字
<html>
    <title>頁面標題</title>
<head>

</head>
<body>
    <select>
        <option>北京</option>
        <option>上海</option>
        <option
>
深圳</option> </select> <div> p標籤外的文字--<p>這裡是標籤的文字</p> </div> <form id="myForm> <input type="text" name="uname" id="inp"/> <input type="text" name="password" id="inp1/> <input type="button" id="but">
</form> <javascript type="text/javascript" src="jQuery/jquery-3.2.1.js></scripte> <script> $('select').val();//獲得當前選座位標籤的值 $('div').text(); //獲得標籤內的所有文字內容輸出結果為: //p標籤外的文字--這裡是標籤的文字 $('div').html()//獲得當前標籤內所有包括標籤的內容輸出結果為: //p標籤外的文字--<p>這裡是標籤的文字</p> //通過Ajax提交表單 $.ajax({ type:"
get", url:"你向哪個頁面發請求的地址", data:$("#myForm").serialize(),//獲得表單資料 success:function(data){ //這裡是處理返回的結果data } }); </script>
</body> </html>