|
示例
1
:
使用var声明一个变量
示例
2
:
不使用var
示例
3
:
变量命名
");
window.frames["iframe_show1072"].document.write(decodeHtml($("textarea#stepcodeTextarea1072").val()));
window.frames["iframe_show1072"].document.close();
$(window.frames["iframe_show1072"]).load(function(){
$("#iframe_show1072").height($("#iframe_show1072").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1072").height($("#iframe_show1072").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
var x = 10;
document.write("变量x的值:"+x);
</script>
<script>
var x = 10;
document.write("变量x的值:"+x);
</script>
");
window.frames["iframe1072"].document.write(decodeHtml(code1072));
window.frames["iframe1072"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1072"]).load(function(){
$("#iframe1072").height($("#iframe1072").contents().find("body").height()+showittryitheight);
});
$("#iframe1072").height($("#iframe1072").contents().find("body").height()+showittryitheight);
alreadyWriteCode1072 = code1072;
$("#rendering1072").hide();
$("#rendered1072").show();
}
var tRereshRetry2DemoPanel1072 = setInterval(rereshRetry2DemoPanel1072,1000);
var binded1072 = false;
$("textarea#stepcodeTextarea1072").keyup(function(){
if(!binded1072){
$(window).bind('beforeunload',function(){
binded1072 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1072 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1072!=newCode){
// window.frames["iframe1072"].document.write("
");
// window.frames["iframe1072"].document.write(decodeHtml($("textarea#stepcodeTextarea1072").val()));
// window.frames["iframe1072"].document.close();
// $(window.frames["iframe1072"]).load(function(){
// $("#iframe1072").height($("#iframe1072").contents().find("body").height()+showittryitheight);
// });
// code1072 = newCode;
// }
});
$(".tryButton1072").click(function(){
$("#tryDiv1072").show();
$("#stepcodeTextarea1072").focus();
$("#stepcodeTextarea1072").height(200);
$("#iframe1072").height(0);
window.frames["iframe1072"].document.write("
");
window.frames["iframe1072"].document.write(decodeHtml($("textarea#stepcodeTextarea1072").val()));
window.frames["iframe1072"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1072"]).load(function(){
$("#iframe1072").height($("#iframe1072").contents().find("body").height()+showittryitheight);
});
$("#iframe1072").height($("#iframe1072").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1072.focus();
editor1072.setSize(null, "250");
$("#rendering1072").hide();
$("#rendered1072").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 editor1072 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1072"), {
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);
}
}
});
editor1072.on("change",function(doc){
if(!binded1072){
$(window).bind('beforeunload',function(){
binded1072 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1072 = newCode;
$("textarea#stepcodeTextarea1072").val(newCode);
if(alreadyWriteCode1072!=code1072){
lastModifedTime1072 = new Date().getTime();
$("#rendering1072").show();
$("#rendered1072").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1072 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1072.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1072").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
关键字var 可有可无,本实例演示不使用var声明的变量
");
window.frames["iframe_show1073"].document.write(decodeHtml($("textarea#stepcodeTextarea1073").val()));
window.frames["iframe_show1073"].document.close();
$(window.frames["iframe_show1073"]).load(function(){
$("#iframe_show1073").height($("#iframe_show1073").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1073").height($("#iframe_show1073").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
x = 10;
document.write("没有用var声明的变量x的值:"+x);
</script>
<script>
x = 10;
document.write("没有用var声明的变量x的值:"+x);
</script>
");
window.frames["iframe1073"].document.write(decodeHtml(code1073));
window.frames["iframe1073"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1073"]).load(function(){
$("#iframe1073").height($("#iframe1073").contents().find("body").height()+showittryitheight);
});
$("#iframe1073").height($("#iframe1073").contents().find("body").height()+showittryitheight);
alreadyWriteCode1073 = code1073;
$("#rendering1073").hide();
$("#rendered1073").show();
}
var tRereshRetry2DemoPanel1073 = setInterval(rereshRetry2DemoPanel1073,1000);
var binded1073 = false;
$("textarea#stepcodeTextarea1073").keyup(function(){
if(!binded1073){
$(window).bind('beforeunload',function(){
binded1073 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1073 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1073!=newCode){
// window.frames["iframe1073"].document.write("
");
// window.frames["iframe1073"].document.write(decodeHtml($("textarea#stepcodeTextarea1073").val()));
// window.frames["iframe1073"].document.close();
// $(window.frames["iframe1073"]).load(function(){
// $("#iframe1073").height($("#iframe1073").contents().find("body").height()+showittryitheight);
// });
// code1073 = newCode;
// }
});
$(".tryButton1073").click(function(){
$("#tryDiv1073").show();
$("#stepcodeTextarea1073").focus();
$("#stepcodeTextarea1073").height(200);
$("#iframe1073").height(0);
window.frames["iframe1073"].document.write("
");
window.frames["iframe1073"].document.write(decodeHtml($("textarea#stepcodeTextarea1073").val()));
window.frames["iframe1073"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1073"]).load(function(){
$("#iframe1073").height($("#iframe1073").contents().find("body").height()+showittryitheight);
});
$("#iframe1073").height($("#iframe1073").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1073.focus();
editor1073.setSize(null, "250");
$("#rendering1073").hide();
$("#rendered1073").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 editor1073 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1073"), {
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);
}
}
});
editor1073.on("change",function(doc){
if(!binded1073){
$(window).bind('beforeunload',function(){
binded1073 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1073 = newCode;
$("textarea#stepcodeTextarea1073").val(newCode);
if(alreadyWriteCode1073!=code1073){
lastModifedTime1073 = new Date().getTime();
$("#rendering1073").show();
$("#rendered1073").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1073 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1073.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1073").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
命名规则和 java差不多可以使用 开头可以用 _$和字母 其他部分可以用 $ _ 字母或者数字 这些是合法的: var $a; var _b; var ab123;
这些是不合法的: var 3$a; var a%; var b*; var (6@
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|