input type = button 的onclick属性调用函数

调用js函数

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
 function fas(){
    alert(1);
 }
</script>
</head>
<body>
    <input type="button" onclick = "fas()" value = "sdsdsd">
</body>
</html>

JQuery调用

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(function(){
 $("#test").click(function(){
    alert(1);
});
});
</script>
</head>
<body>
    <input id = "test" type="button" value = "sdsdsd">    //无onclick,隐含调用
</body>
</html>

  

posted @ 2021-03-15 14:04  清语堂  阅读(2432)  评论(0编辑  收藏  举报