JQuery爲html中標籤設置響應的事件函數

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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章