如题,代码中三元运算符改写成if else则可以,为甚么?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用鼠标滚轮滚动控制图片的缩小放大</title>
<script language="javascript">
function bbimg(o){
var zoom=parseInt(o.style.zoom, 10)||100;
zoom+=event.wheelDelta/12;
zoom < 50 ? 50 : (zoom > 200 ? 200 : zoom); //目标
console.log(zoom);
o.style.zoom=zoom+'%';
return false;
}
</script>
</head>
<body>
<p>将鼠标放在图片上,点击一下,然后滚动鼠标滚轮试试看</p>
<p><img border="0" src="/images/pulpit.jpg" onmousewheel="return bbimg(this)"></p>
</body>
</html>
慕田峪7331174
相关分类