首页 > IT职业 > > 函数能使用函数以外的变量吗?
为什么这样可以输出
function fn(){
var txt=document.getElementById("txt").value;
var mydate =new Date();
mydate.setTime(mydate.getTime()+txt*60*60*1000);
document.write("延迟后的时间为:"+mydate+"<br/>");
}
而这样不可以呢?
var txt=document.getElementById("txt").value;
function fn(){
var mydate =new Date();
mydate.setTime(mydate.getTime()+txt*60*60*1000);
document.write("延迟后的时间为:"+mydate+"<br/>");
}
1 | <br> |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27/viewspace-3133847/ ,如需转载,请注明出处,否则将追究法律责任。