|
示例
1
:
刷新当前页面
示例
2
:
跳转到另一个页面
示例
3
:
Location的其他属性
");
window.frames["iframe_show1163"].document.write(decodeHtml($("textarea#stepcodeTextarea1163").val()));
window.frames["iframe_show1163"].document.close();
$(window.frames["iframe_show1163"]).load(function(){
$("#iframe_show1163").height($("#iframe_show1163").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1163").height($("#iframe_show1163").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<span>当前时间:</span>
<script>
var d = new Date();
document.write(d.getHours());
document.write(":");
document.write(d.getMinutes());
document.write(":");
document.write(d.getSeconds());
document.write(":");
document.write(d.getMilliseconds());
function refresh(){
location.reload();
}
</script>
<br>
<button onclick="refresh()">刷新当前页面</button>
<span>当前时间:</span>
<script>
var d = new Date();
document.write(d.getHours());
document.write(":");
document.write(d.getMinutes());
document.write(":");
document.write(d.getSeconds());
document.write(":");
document.write(d.getMilliseconds());
function refresh(){
location.reload();
}
</script>
<br>
<button onclick="refresh()">刷新当前页面</button>
");
window.frames["iframe1163"].document.write(decodeHtml(code1163));
window.frames["iframe1163"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1163"]).load(function(){
$("#iframe1163").height($("#iframe1163").contents().find("body").height()+showittryitheight);
});
$("#iframe1163").height($("#iframe1163").contents().find("body").height()+showittryitheight);
alreadyWriteCode1163 = code1163;
$("#rendering1163").hide();
$("#rendered1163").show();
}
var tRereshRetry2DemoPanel1163 = setInterval(rereshRetry2DemoPanel1163,1000);
var binded1163 = false;
$("textarea#stepcodeTextarea1163").keyup(function(){
if(!binded1163){
$(window).bind('beforeunload',function(){
binded1163 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1163 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1163!=newCode){
// window.frames["iframe1163"].document.write("
");
// window.frames["iframe1163"].document.write(decodeHtml($("textarea#stepcodeTextarea1163").val()));
// window.frames["iframe1163"].document.close();
// $(window.frames["iframe1163"]).load(function(){
// $("#iframe1163").height($("#iframe1163").contents().find("body").height()+showittryitheight);
// });
// code1163 = newCode;
// }
});
$(".tryButton1163").click(function(){
$("#tryDiv1163").show();
$("#stepcodeTextarea1163").focus();
$("#stepcodeTextarea1163").height(200);
$("#iframe1163").height(0);
window.frames["iframe1163"].document.write("
");
window.frames["iframe1163"].document.write(decodeHtml($("textarea#stepcodeTextarea1163").val()));
window.frames["iframe1163"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1163"]).load(function(){
$("#iframe1163").height($("#iframe1163").contents().find("body").height()+showittryitheight);
});
$("#iframe1163").height($("#iframe1163").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1163.focus();
editor1163.setSize(null, "250");
$("#rendering1163").hide();
$("#rendered1163").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 editor1163 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1163"), {
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);
}
}
});
editor1163.on("change",function(doc){
if(!binded1163){
$(window).bind('beforeunload',function(){
binded1163 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1163 = newCode;
$("textarea#stepcodeTextarea1163").val(newCode);
if(alreadyWriteCode1163!=code1163){
lastModifedTime1163 = new Date().getTime();
$("#rendering1163").show();
$("#rendered1163").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1163 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1163.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1163").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show1164"].document.write(decodeHtml($("textarea#stepcodeTextarea1164").val()));
window.frames["iframe_show1164"].document.close();
$(window.frames["iframe_show1164"]).load(function(){
$("#iframe_show1164").height($("#iframe_show1164").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1164").height($("#iframe_show1164").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
function jump(){
//方法1
//location="/";
//方法2
location.assign("/");
}
</script>
<br>
<button onclick="jump()">跳转到首页</button>
<script>
function jump(){
//方法1
//location="/";
//方法2
location.assign("/");
}
</script>
<br>
<button onclick="jump()">跳转到首页</button>
");
window.frames["iframe1164"].document.write(decodeHtml(code1164));
window.frames["iframe1164"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1164"]).load(function(){
$("#iframe1164").height($("#iframe1164").contents().find("body").height()+showittryitheight);
});
$("#iframe1164").height($("#iframe1164").contents().find("body").height()+showittryitheight);
alreadyWriteCode1164 = code1164;
$("#rendering1164").hide();
$("#rendered1164").show();
}
var tRereshRetry2DemoPanel1164 = setInterval(rereshRetry2DemoPanel1164,1000);
var binded1164 = false;
$("textarea#stepcodeTextarea1164").keyup(function(){
if(!binded1164){
$(window).bind('beforeunload',function(){
binded1164 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1164 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1164!=newCode){
// window.frames["iframe1164"].document.write("
");
// window.frames["iframe1164"].document.write(decodeHtml($("textarea#stepcodeTextarea1164").val()));
// window.frames["iframe1164"].document.close();
// $(window.frames["iframe1164"]).load(function(){
// $("#iframe1164").height($("#iframe1164").contents().find("body").height()+showittryitheight);
// });
// code1164 = newCode;
// }
});
$(".tryButton1164").click(function(){
$("#tryDiv1164").show();
$("#stepcodeTextarea1164").focus();
$("#stepcodeTextarea1164").height(200);
$("#iframe1164").height(0);
window.frames["iframe1164"].document.write("
");
window.frames["iframe1164"].document.write(decodeHtml($("textarea#stepcodeTextarea1164").val()));
window.frames["iframe1164"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1164"]).load(function(){
$("#iframe1164").height($("#iframe1164").contents().find("body").height()+showittryitheight);
});
$("#iframe1164").height($("#iframe1164").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1164.focus();
editor1164.setSize(null, "250");
$("#rendering1164").hide();
$("#rendered1164").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 editor1164 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1164"), {
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);
}
}
});
editor1164.on("change",function(doc){
if(!binded1164){
$(window).bind('beforeunload',function(){
binded1164 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1164 = newCode;
$("textarea#stepcodeTextarea1164").val(newCode);
if(alreadyWriteCode1164!=code1164){
lastModifedTime1164 = new Date().getTime();
$("#rendering1164").show();
$("#rendered1164").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1164 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1164.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1164").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show1165"].document.write(decodeHtml($("textarea#stepcodeTextarea1165").val()));
window.frames["iframe_show1165"].document.close();
$(window.frames["iframe_show1165"]).load(function(){
$("#iframe_show1165").height($("#iframe_show1165").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1165").height($("#iframe_show1165").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("协议 location.protocol:"+location.protocol);
p("主机名 location.hostname:"+location.hostname);
p("端口号 (默认是80,没有即表示80端口)location.port:"+location.port);
p("主机加端口号 location.host:"+location.host);
p("访问的路径 location.pathname:"+location.pathname);
p("锚点 location.hash:"+location.hash);
p("参数列表 location.search"+location.search);
</script>
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("协议 location.protocol:"+location.protocol);
p("主机名 location.hostname:"+location.hostname);
p("端口号 (默认是80,没有即表示80端口)location.port:"+location.port);
p("主机加端口号 location.host:"+location.host);
p("访问的路径 location.pathname:"+location.pathname);
p("锚点 location.hash:"+location.hash);
p("参数列表 location.search"+location.search);
</script>
");
window.frames["iframe1165"].document.write(decodeHtml(code1165));
window.frames["iframe1165"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1165"]).load(function(){
$("#iframe1165").height($("#iframe1165").contents().find("body").height()+showittryitheight);
});
$("#iframe1165").height($("#iframe1165").contents().find("body").height()+showittryitheight);
alreadyWriteCode1165 = code1165;
$("#rendering1165").hide();
$("#rendered1165").show();
}
var tRereshRetry2DemoPanel1165 = setInterval(rereshRetry2DemoPanel1165,1000);
var binded1165 = false;
$("textarea#stepcodeTextarea1165").keyup(function(){
if(!binded1165){
$(window).bind('beforeunload',function(){
binded1165 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1165 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1165!=newCode){
// window.frames["iframe1165"].document.write("
");
// window.frames["iframe1165"].document.write(decodeHtml($("textarea#stepcodeTextarea1165").val()));
// window.frames["iframe1165"].document.close();
// $(window.frames["iframe1165"]).load(function(){
// $("#iframe1165").height($("#iframe1165").contents().find("body").height()+showittryitheight);
// });
// code1165 = newCode;
// }
});
$(".tryButton1165").click(function(){
$("#tryDiv1165").show();
$("#stepcodeTextarea1165").focus();
$("#stepcodeTextarea1165").height(200);
$("#iframe1165").height(0);
window.frames["iframe1165"].document.write("
");
window.frames["iframe1165"].document.write(decodeHtml($("textarea#stepcodeTextarea1165").val()));
window.frames["iframe1165"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1165"]).load(function(){
$("#iframe1165").height($("#iframe1165").contents().find("body").height()+showittryitheight);
});
$("#iframe1165").height($("#iframe1165").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1165.focus();
editor1165.setSize(null, "250");
$("#rendering1165").hide();
$("#rendered1165").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 editor1165 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1165"), {
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);
}
}
});
editor1165.on("change",function(doc){
if(!binded1165){
$(window).bind('beforeunload',function(){
binded1165 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1165 = newCode;
$("textarea#stepcodeTextarea1165").val(newCode);
if(alreadyWriteCode1165!=code1165){
lastModifedTime1165 = new Date().getTime();
$("#rendering1165").show();
$("#rendered1165").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1165 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1165.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1165").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|