|
示例
1
:
JSON对象与JavaScript对象
示例
2
:
字符串转为JSON对象
示例
3
:
JSON 对象转换为字符串
示例
1
:
JSON对象与JavaScript对象
顶
折
");
window.frames["iframe_show1242"].document.write(decodeHtml($("textarea#stepcodeTextarea1242").val()));
window.frames["iframe_show1242"].document.close();
$(window.frames["iframe_show1242"]).load(function(){
$("#iframe_show1242").height($("#iframe_show1242").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1242").height($("#iframe_show1242").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
var s1 = "{\"name\":\"盖伦\"";
var s2 = ",\"hp\":616}";
var s3 = s1+s2;
document.write("这是一个JSON格式的字符串:" + s3);
document.write("<br>");
var gareen = eval("("+s3+")");
document.write("这是一个JSON对象: " + gareen);
</script>
<script>
var s1 = "{\"name\":\"盖伦\"";
var s2 = ",\"hp\":616}";
var s3 = s1+s2;
document.write("这是一个JSON格式的字符串:" + s3);
document.write("<br>");
var gareen = eval("("+s3+")");
document.write("这是一个JSON对象: " + gareen);
</script>
");
window.frames["iframe1242"].document.write(decodeHtml(code1242));
window.frames["iframe1242"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1242"]).load(function(){
$("#iframe1242").height($("#iframe1242").contents().find("body").height()+showittryitheight);
});
$("#iframe1242").height($("#iframe1242").contents().find("body").height()+showittryitheight);
alreadyWriteCode1242 = code1242;
$("#rendering1242").hide();
$("#rendered1242").show();
}
var tRereshRetry2DemoPanel1242 = setInterval(rereshRetry2DemoPanel1242,1000);
var binded1242 = false;
$("textarea#stepcodeTextarea1242").keyup(function(){
if(!binded1242){
$(window).bind('beforeunload',function(){
binded1242 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1242 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1242!=newCode){
// window.frames["iframe1242"].document.write("
");
// window.frames["iframe1242"].document.write(decodeHtml($("textarea#stepcodeTextarea1242").val()));
// window.frames["iframe1242"].document.close();
// $(window.frames["iframe1242"]).load(function(){
// $("#iframe1242").height($("#iframe1242").contents().find("body").height()+showittryitheight);
// });
// code1242 = newCode;
// }
});
$(".tryButton1242").click(function(){
$("#tryDiv1242").show();
$("#stepcodeTextarea1242").focus();
$("#stepcodeTextarea1242").height(200);
$("#iframe1242").height(0);
window.frames["iframe1242"].document.write("
");
window.frames["iframe1242"].document.write(decodeHtml($("textarea#stepcodeTextarea1242").val()));
window.frames["iframe1242"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1242"]).load(function(){
$("#iframe1242").height($("#iframe1242").contents().find("body").height()+showittryitheight);
});
$("#iframe1242").height($("#iframe1242").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1242.focus();
editor1242.setSize(null, "250");
$("#rendering1242").hide();
$("#rendered1242").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 editor1242 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1242"), {
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);
}
}
});
editor1242.on("change",function(doc){
if(!binded1242){
$(window).bind('beforeunload',function(){
binded1242 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1242 = newCode;
$("textarea#stepcodeTextarea1242").val(newCode);
if(alreadyWriteCode1242!=code1242){
lastModifedTime1242 = new Date().getTime();
$("#rendering1242").show();
$("#rendered1242").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1242 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1242.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1242").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
json 对象因为是一个javascript对象,所以如果直接打印的话,看不到里面的内容。 有时候要看看这个对象是不是我们期望的,所以需要通过 JSON.stringify 函数把它转换为 字符串
");
window.frames["iframe_show7833"].document.write(decodeHtml($("textarea#stepcodeTextarea7833").val()));
window.frames["iframe_show7833"].document.close();
$(window.frames["iframe_show7833"]).load(function(){
$("#iframe_show7833").height($("#iframe_show7833").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7833").height($("#iframe_show7833").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
var hero = {"name":"盖伦","hp":"616"};
document.write("这是一个json 对象:"+ hero);
document.write("<br>");
var heroString = JSON.stringify(hero)
document.write("这是一个json 字符串:"+ heroString );
</script>
<script>
var hero = {"name":"盖伦","hp":"616"};
document.write("这是一个json 对象:"+ hero);
document.write("<br>");
var heroString = JSON.stringify(hero)
document.write("这是一个json 字符串:"+ heroString );
</script>
");
window.frames["iframe7833"].document.write(decodeHtml(code7833));
window.frames["iframe7833"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7833"]).load(function(){
$("#iframe7833").height($("#iframe7833").contents().find("body").height()+showittryitheight);
});
$("#iframe7833").height($("#iframe7833").contents().find("body").height()+showittryitheight);
alreadyWriteCode7833 = code7833;
$("#rendering7833").hide();
$("#rendered7833").show();
}
var tRereshRetry2DemoPanel7833 = setInterval(rereshRetry2DemoPanel7833,1000);
var binded7833 = false;
$("textarea#stepcodeTextarea7833").keyup(function(){
if(!binded7833){
$(window).bind('beforeunload',function(){
binded7833 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7833 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7833!=newCode){
// window.frames["iframe7833"].document.write("
");
// window.frames["iframe7833"].document.write(decodeHtml($("textarea#stepcodeTextarea7833").val()));
// window.frames["iframe7833"].document.close();
// $(window.frames["iframe7833"]).load(function(){
// $("#iframe7833").height($("#iframe7833").contents().find("body").height()+showittryitheight);
// });
// code7833 = newCode;
// }
});
$(".tryButton7833").click(function(){
$("#tryDiv7833").show();
$("#stepcodeTextarea7833").focus();
$("#stepcodeTextarea7833").height(200);
$("#iframe7833").height(0);
window.frames["iframe7833"].document.write("
");
window.frames["iframe7833"].document.write(decodeHtml($("textarea#stepcodeTextarea7833").val()));
window.frames["iframe7833"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7833"]).load(function(){
$("#iframe7833").height($("#iframe7833").contents().find("body").height()+showittryitheight);
});
$("#iframe7833").height($("#iframe7833").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7833.focus();
editor7833.setSize(null, "250");
$("#rendering7833").hide();
$("#rendered7833").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 editor7833 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7833"), {
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);
}
}
});
editor7833.on("change",function(doc){
if(!binded7833){
$(window).bind('beforeunload',function(){
binded7833 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7833 = newCode;
$("textarea#stepcodeTextarea7833").val(newCode);
if(alreadyWriteCode7833!=code7833){
lastModifedTime7833 = new Date().getTime();
$("#rendering7833").show();
$("#rendered7833").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7833 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7833.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7833").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|