|
示例
1
:
参数的作用域
示例
2
:
全局变量的作用域
一个参数的作用域就在这个函数内部,超出函数就看不见该参数了
");
window.frames["iframe_show1096"].document.write(decodeHtml($("textarea#stepcodeTextarea1096").val()));
window.frames["iframe_show1096"].document.close();
$(window.frames["iframe_show1096"]).load(function(){
$("#iframe_show1096").height($("#iframe_show1096").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1096").height($("#iframe_show1096").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
function f1(a){
document.write('参数的作用域在函数以内,其值是 '+a);//参数a的作用范围,所以打印出来是5;
}
function f2(){
document.write('在函数里不能访问其他函数的参数'+a); //不在参数a的作用范围,是一个未声明的变量,无法打印
}
f1(5);
f2();
document.write('在函数外也不能访问'+a);//也不在参数a的作用范围,是一个未声明的变量,无法打印
</script>
<script>
function f1(a){
document.write('参数的作用域在函数以内,其值是 '+a);//参数a的作用范围,所以打印出来是5;
}
function f2(){
document.write('在函数里不能访问其他函数的参数'+a); //不在参数a的作用范围,是一个未声明的变量,无法打印
}
f1(5);
f2();
document.write('在函数外也不能访问'+a);//也不在参数a的作用范围,是一个未声明的变量,无法打印
</script>
");
window.frames["iframe1096"].document.write(decodeHtml(code1096));
window.frames["iframe1096"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1096"]).load(function(){
$("#iframe1096").height($("#iframe1096").contents().find("body").height()+showittryitheight);
});
$("#iframe1096").height($("#iframe1096").contents().find("body").height()+showittryitheight);
alreadyWriteCode1096 = code1096;
$("#rendering1096").hide();
$("#rendered1096").show();
}
var tRereshRetry2DemoPanel1096 = setInterval(rereshRetry2DemoPanel1096,1000);
var binded1096 = false;
$("textarea#stepcodeTextarea1096").keyup(function(){
if(!binded1096){
$(window).bind('beforeunload',function(){
binded1096 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1096 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1096!=newCode){
// window.frames["iframe1096"].document.write("
");
// window.frames["iframe1096"].document.write(decodeHtml($("textarea#stepcodeTextarea1096").val()));
// window.frames["iframe1096"].document.close();
// $(window.frames["iframe1096"]).load(function(){
// $("#iframe1096").height($("#iframe1096").contents().find("body").height()+showittryitheight);
// });
// code1096 = newCode;
// }
});
$(".tryButton1096").click(function(){
$("#tryDiv1096").show();
$("#stepcodeTextarea1096").focus();
$("#stepcodeTextarea1096").height(200);
$("#iframe1096").height(0);
window.frames["iframe1096"].document.write("
");
window.frames["iframe1096"].document.write(decodeHtml($("textarea#stepcodeTextarea1096").val()));
window.frames["iframe1096"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1096"]).load(function(){
$("#iframe1096").height($("#iframe1096").contents().find("body").height()+showittryitheight);
});
$("#iframe1096").height($("#iframe1096").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1096.focus();
editor1096.setSize(null, "250");
$("#rendering1096").hide();
$("#rendered1096").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor1096 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1096"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor1096.on("change",function(doc){
if(!binded1096){
$(window).bind('beforeunload',function(){
binded1096 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1096 = newCode;
$("textarea#stepcodeTextarea1096").val(newCode);
if(alreadyWriteCode1096!=code1096){
lastModifedTime1096 = new Date().getTime();
$("#rendering1096").show();
$("#rendered1096").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1096 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1096.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1096").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show1097"].document.write(decodeHtml($("textarea#stepcodeTextarea1097").val()));
window.frames["iframe_show1097"].document.close();
$(window.frames["iframe_show1097"]).load(function(){
$("#iframe_show1097").height($("#iframe_show1097").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1097").height($("#iframe_show1097").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
var a = 0; //定义在函数前面,即全局变量,所有函数都可以访问
function f1(){
document.write('通过函数f1 设置全局变量a的值 为 5');
a = 5; //能够访问
}
function f2(){
document.write('通过函数f2 访问并打印全局变量a的值 '+a); //能够访问
}
f1(); //通过f1,设置a的值
document.write('<br>');
f2(); //通过f2, 打印a的值
</script>
<script>
var a = 0; //定义在函数前面,即全局变量,所有函数都可以访问
function f1(){
document.write('通过函数f1 设置全局变量a的值 为 5');
a = 5; //能够访问
}
function f2(){
document.write('通过函数f2 访问并打印全局变量a的值 '+a); //能够访问
}
f1(); //通过f1,设置a的值
document.write('<br>');
f2(); //通过f2, 打印a的值
</script>
");
window.frames["iframe1097"].document.write(decodeHtml(code1097));
window.frames["iframe1097"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1097"]).load(function(){
$("#iframe1097").height($("#iframe1097").contents().find("body").height()+showittryitheight);
});
$("#iframe1097").height($("#iframe1097").contents().find("body").height()+showittryitheight);
alreadyWriteCode1097 = code1097;
$("#rendering1097").hide();
$("#rendered1097").show();
}
var tRereshRetry2DemoPanel1097 = setInterval(rereshRetry2DemoPanel1097,1000);
var binded1097 = false;
$("textarea#stepcodeTextarea1097").keyup(function(){
if(!binded1097){
$(window).bind('beforeunload',function(){
binded1097 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1097 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1097!=newCode){
// window.frames["iframe1097"].document.write("
");
// window.frames["iframe1097"].document.write(decodeHtml($("textarea#stepcodeTextarea1097").val()));
// window.frames["iframe1097"].document.close();
// $(window.frames["iframe1097"]).load(function(){
// $("#iframe1097").height($("#iframe1097").contents().find("body").height()+showittryitheight);
// });
// code1097 = newCode;
// }
});
$(".tryButton1097").click(function(){
$("#tryDiv1097").show();
$("#stepcodeTextarea1097").focus();
$("#stepcodeTextarea1097").height(200);
$("#iframe1097").height(0);
window.frames["iframe1097"].document.write("
");
window.frames["iframe1097"].document.write(decodeHtml($("textarea#stepcodeTextarea1097").val()));
window.frames["iframe1097"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1097"]).load(function(){
$("#iframe1097").height($("#iframe1097").contents().find("body").height()+showittryitheight);
});
$("#iframe1097").height($("#iframe1097").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1097.focus();
editor1097.setSize(null, "250");
$("#rendering1097").hide();
$("#rendered1097").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor1097 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1097"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor1097.on("change",function(doc){
if(!binded1097){
$(window).bind('beforeunload',function(){
binded1097 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1097 = newCode;
$("textarea#stepcodeTextarea1097").val(newCode);
if(alreadyWriteCode1097!=code1097){
lastModifedTime1097 = new Date().getTime();
$("#rendering1097").show();
$("#rendered1097").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1097 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1097.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1097").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|