关键字
简介
示例代码
== != > >= < <=
基本逻辑运算符
示例代码
=== !==
绝对等,绝对不等于
示例代码
?:
三目运算符
示例代码
示例
1
:
基本逻辑运算符
示例
2
:
绝对等,绝对不等于
示例
3
:
三目运算符
基本逻辑运算符 包含如下 :
==
!=
>
>=
返回一个Boolean类型的值,true或者false
");
window.frames["iframe_show1103"].document.write(decodeHtml($("textarea#stepcodeTextarea1103").val()));
window.frames["iframe_show1103"].document.close();
$(window.frames["iframe_show1103"]).load(function(){
$("#iframe_show1103").height($("#iframe_show1103").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1103").height($("#iframe_show1103").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
运行效果
代码比较
复制代码
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("1==2: "+(1==2));
p("1!=2: "+(1!=2));
p("1>2: "+(1>2));
p("1<2: "+(1<2));
p("1>=2: "+(1>=2));
</script>
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("1==2: "+(1==2));
p("1!=2: "+(1!=2));
p("1>2: "+(1>2));
p("1<2: "+(1<2));
p("1>=2: "+(1>=2));
</script>
");
window.frames["iframe1103"].document.write(decodeHtml(code1103));
window.frames["iframe1103"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1103"]).load(function(){
$("#iframe1103").height($("#iframe1103").contents().find("body").height()+showittryitheight);
});
$("#iframe1103").height($("#iframe1103").contents().find("body").height()+showittryitheight);
alreadyWriteCode1103 = code1103;
$("#rendering1103").hide();
$("#rendered1103").show();
}
var tRereshRetry2DemoPanel1103 = setInterval(rereshRetry2DemoPanel1103,1000);
var binded1103 = false;
$("textarea#stepcodeTextarea1103").keyup(function(){
if(!binded1103){
$(window).bind('beforeunload',function(){
binded1103 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1103 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1103!=newCode){
// window.frames["iframe1103"].document.write("
");
// window.frames["iframe1103"].document.write(decodeHtml($("textarea#stepcodeTextarea1103").val()));
// window.frames["iframe1103"].document.close();
// $(window.frames["iframe1103"]).load(function(){
// $("#iframe1103").height($("#iframe1103").contents().find("body").height()+showittryitheight);
// });
// code1103 = newCode;
// }
});
$(".tryButton1103").click(function(){
$("#tryDiv1103").show();
$("#stepcodeTextarea1103").focus();
$("#stepcodeTextarea1103").height(200);
$("#iframe1103").height(0);
window.frames["iframe1103"].document.write("
");
window.frames["iframe1103"].document.write(decodeHtml($("textarea#stepcodeTextarea1103").val()));
window.frames["iframe1103"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1103"]).load(function(){
$("#iframe1103").height($("#iframe1103").contents().find("body").height()+showittryitheight);
});
$("#iframe1103").height($("#iframe1103").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1103.focus();
editor1103.setSize(null, "250");
$("#rendering1103").hide();
$("#rendered1103").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 editor1103 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1103"), {
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);
}
}
});
editor1103.on("change",function(doc){
if(!binded1103){
$(window).bind('beforeunload',function(){
binded1103 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1103 = newCode;
$("textarea#stepcodeTextarea1103").val(newCode);
if(alreadyWriteCode1103!=code1103){
lastModifedTime1103 = new Date().getTime();
$("#rendering1103").show();
$("#rendered1103").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1103 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1103.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1103").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
试一下
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
渲染中
渲染完成
与==进行值是否相等的判断不同 ,绝对等 ===还会进行 类型的判断 比如 数字1和 字符串'1'比较,值是相等的,但是类型不同 所以==会返回true,但是===会返回false 绝对不等于!== 与上是一个道理
");
window.frames["iframe_show1104"].document.write(decodeHtml($("textarea#stepcodeTextarea1104").val()));
window.frames["iframe_show1104"].document.close();
$(window.frames["iframe_show1104"]).load(function(){
$("#iframe_show1104").height($("#iframe_show1104").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1104").height($("#iframe_show1104").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
运行效果
代码比较
复制代码
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("1=='1': "+(1=='1'));
p("1==='1': "+(1==='1'));
</script>
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("1=='1': "+(1=='1'));
p("1==='1': "+(1==='1'));
</script>
");
window.frames["iframe1104"].document.write(decodeHtml(code1104));
window.frames["iframe1104"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1104"]).load(function(){
$("#iframe1104").height($("#iframe1104").contents().find("body").height()+showittryitheight);
});
$("#iframe1104").height($("#iframe1104").contents().find("body").height()+showittryitheight);
alreadyWriteCode1104 = code1104;
$("#rendering1104").hide();
$("#rendered1104").show();
}
var tRereshRetry2DemoPanel1104 = setInterval(rereshRetry2DemoPanel1104,1000);
var binded1104 = false;
$("textarea#stepcodeTextarea1104").keyup(function(){
if(!binded1104){
$(window).bind('beforeunload',function(){
binded1104 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1104 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1104!=newCode){
// window.frames["iframe1104"].document.write("
");
// window.frames["iframe1104"].document.write(decodeHtml($("textarea#stepcodeTextarea1104").val()));
// window.frames["iframe1104"].document.close();
// $(window.frames["iframe1104"]).load(function(){
// $("#iframe1104").height($("#iframe1104").contents().find("body").height()+showittryitheight);
// });
// code1104 = newCode;
// }
});
$(".tryButton1104").click(function(){
$("#tryDiv1104").show();
$("#stepcodeTextarea1104").focus();
$("#stepcodeTextarea1104").height(200);
$("#iframe1104").height(0);
window.frames["iframe1104"].document.write("
");
window.frames["iframe1104"].document.write(decodeHtml($("textarea#stepcodeTextarea1104").val()));
window.frames["iframe1104"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1104"]).load(function(){
$("#iframe1104").height($("#iframe1104").contents().find("body").height()+showittryitheight);
});
$("#iframe1104").height($("#iframe1104").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1104.focus();
editor1104.setSize(null, "250");
$("#rendering1104").hide();
$("#rendered1104").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 editor1104 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1104"), {
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);
}
}
});
editor1104.on("change",function(doc){
if(!binded1104){
$(window).bind('beforeunload',function(){
binded1104 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1104 = newCode;
$("textarea#stepcodeTextarea1104").val(newCode);
if(alreadyWriteCode1104!=code1104){
lastModifedTime1104 = new Date().getTime();
$("#rendering1104").show();
$("#rendered1104").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1104 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1104.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1104").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
试一下
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
渲染中
渲染完成
三目运算符 ?: 有三个操作数 如果第一个返回true,就返回第二个操作符 否则就返回第三个操作符。
");
window.frames["iframe_show1105"].document.write(decodeHtml($("textarea#stepcodeTextarea1105").val()));
window.frames["iframe_show1105"].document.close();
$(window.frames["iframe_show1105"]).load(function(){
$("#iframe_show1105").height($("#iframe_show1105").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1105").height($("#iframe_show1105").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
运行效果
代码比较
复制代码
<script>
var age = 15;
var movie = age<18?"卡通":"你懂的";
document.write('使用?: 三相运算法进行判断。 <br>');
document.write('age<18?"卡通":"你懂的" <br>表示当年纪小于18的时候,就看卡通,否则就看 你懂得<br>');
document.write('而age变量的值是15,所以返回 '+movie);
</script>
<script>
var age = 15;
var movie = age<18?"卡通":"你懂的";
document.write('使用?: 三相运算法进行判断。 <br>');
document.write('age<18?"卡通":"你懂的" <br>表示当年纪小于18的时候,就看卡通,否则就看 你懂得<br>');
document.write('而age变量的值是15,所以返回 '+movie);
</script>
");
window.frames["iframe1105"].document.write(decodeHtml(code1105));
window.frames["iframe1105"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1105"]).load(function(){
$("#iframe1105").height($("#iframe1105").contents().find("body").height()+showittryitheight);
});
$("#iframe1105").height($("#iframe1105").contents().find("body").height()+showittryitheight);
alreadyWriteCode1105 = code1105;
$("#rendering1105").hide();
$("#rendered1105").show();
}
var tRereshRetry2DemoPanel1105 = setInterval(rereshRetry2DemoPanel1105,1000);
var binded1105 = false;
$("textarea#stepcodeTextarea1105").keyup(function(){
if(!binded1105){
$(window).bind('beforeunload',function(){
binded1105 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1105 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1105!=newCode){
// window.frames["iframe1105"].document.write("
");
// window.frames["iframe1105"].document.write(decodeHtml($("textarea#stepcodeTextarea1105").val()));
// window.frames["iframe1105"].document.close();
// $(window.frames["iframe1105"]).load(function(){
// $("#iframe1105").height($("#iframe1105").contents().find("body").height()+showittryitheight);
// });
// code1105 = newCode;
// }
});
$(".tryButton1105").click(function(){
$("#tryDiv1105").show();
$("#stepcodeTextarea1105").focus();
$("#stepcodeTextarea1105").height(200);
$("#iframe1105").height(0);
window.frames["iframe1105"].document.write("
");
window.frames["iframe1105"].document.write(decodeHtml($("textarea#stepcodeTextarea1105").val()));
window.frames["iframe1105"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1105"]).load(function(){
$("#iframe1105").height($("#iframe1105").contents().find("body").height()+showittryitheight);
});
$("#iframe1105").height($("#iframe1105").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1105.focus();
editor1105.setSize(null, "250");
$("#rendering1105").hide();
$("#rendered1105").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 editor1105 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1105"), {
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);
}
}
});
editor1105.on("change",function(doc){
if(!binded1105){
$(window).bind('beforeunload',function(){
binded1105 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1105 = newCode;
$("textarea#stepcodeTextarea1105").val(newCode);
if(alreadyWriteCode1105!=code1105){
lastModifedTime1105 = new Date().getTime();
$("#rendering1105").show();
$("#rendered1105").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1105 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1105.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1105").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
试一下
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
渲染中
渲染完成
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆