window.onload = function(){
var odiv = document.getElementById('div1');
odiv.onclick = function(){
alert('Hello');
}
}
一个没有函数名的函数就是匿名函数
函数传参
<script type = "text/javascript">
widow.onload = function (){
var a = document.getElementById('div1');
function changeStyle(sty1,va1){
a.style[sty1] = va1;
}
changeStyle('color', 'red');
changeStyle('background','gold');
}
</script>
return关键字
window.onload = function (){
input01 = document.getElementById('input01');
input02 = document.getElementById('input02');
btn = document.getElementById('btn');
btn.onclick = function(){
var val01 = input01.value;
var valo2 = input02.value;
var result = add(val01,val02);
alert(result)
};
funtion add(a,b){
var c = parseInt(a) + parseInt(b);
return c;
}
}
1.return返回一个值
2.也可以用于结束语句
网友评论