Javascript和JQuery函数定义方式

Javascript 函数定义方式

1、function show() {     }

2、var cal = function() {     },必须先声明才能调用

示例:

<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript">
function show(event, obj) {
    // 事件event  函数都是一个事件
    alert(event.target.id + "  " + obj.id);    
}

var num = function() {
    return 4;
}
// 切记不要写成 var sum = num;
var  sum = num();
alert(ss);
</script>
</head>
<body>
<div>
<p id="p1" onclick ="show(event, this)">If you click on me, I will show something</p>
</div>
</body>

</html> 

 JQuery事件

1、$("#id").click(function(){  });     注:HTML和JS混合的页面,此法的调用位置要放到HTML尾部

$("#scanning").click(function () {    
                                  alert("000");
                                  }
                                   
原文地址:https://www.cnblogs.com/Kevin00/p/7608331.html