1.下面代碼實現通過jquery爲html中的button標籤、和input標籤設置響應的響應函數;
其中input類型的標籤有兩個響應函數,點擊一次,會分別執行兩個響應的函數。
<html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("ceshi1.php",{
name:"菜鳥教程",
url:"http://www.runoob.com"
},
function(data,status){
alert("數據: \n" + data + "\n狀態: " + status);
});
});
$("input").click(function(){ //所有input控件都會執行的函數
$.post("ceshi1.php",{
name:"菜鳥教程",
url:"http://www.runoob.com"
},
function(data,status){
alert("數據: \n" + data + "\n狀態: " + status);
});
});
});
function shishi1()
{
alert("shishi1");
}
</script>
</head>
<body>
<button>發送一個 HTTP POST 請求頁面並獲取返回內容</button>
<!--下面input控件會執行兩個函數,分別是shishi1()函數和input()響應函數;-->
<input type="button" onclick="shishi1()" name="buttonone">
</body>
</html>