|
示例
1
:
显示图像
示例
2
:
同级目录图像
示例
3
:
上级目录图像
示例
4
:
其他目录图像
示例
5
:
设置图像的大小
示例
6
:
图像居中
示例
7
:
替换图片上的文字
");
window.frames["iframe_show330"].document.write(decodeHtml($("textarea#stepcodeTextarea330").val()));
window.frames["iframe_show330"].document.close();
$(window.frames["iframe_show330"]).load(function(){
$("#iframe_show330").height($("#iframe_show330").contents().find("body").height()+showittryitheight);
});
$("#iframe_show330").height($("#iframe_show330").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<img src="http://127.0.0.1/example.gif"/>
<img src="http://127.0.0.1/example.gif"/>
");
window.frames["iframe330"].document.write(decodeHtml(code330));
window.frames["iframe330"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe330"]).load(function(){
$("#iframe330").height($("#iframe330").contents().find("body").height()+showittryitheight);
});
$("#iframe330").height($("#iframe330").contents().find("body").height()+showittryitheight);
alreadyWriteCode330 = code330;
$("#rendering330").hide();
$("#rendered330").show();
}
var tRereshRetry2DemoPanel330 = setInterval(rereshRetry2DemoPanel330,1000);
var binded330 = false;
$("textarea#stepcodeTextarea330").keyup(function(){
if(!binded330){
$(window).bind('beforeunload',function(){
binded330 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code330 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code330!=newCode){
// window.frames["iframe330"].document.write("
");
// window.frames["iframe330"].document.write(decodeHtml($("textarea#stepcodeTextarea330").val()));
// window.frames["iframe330"].document.close();
// $(window.frames["iframe330"]).load(function(){
// $("#iframe330").height($("#iframe330").contents().find("body").height()+showittryitheight);
// });
// code330 = newCode;
// }
});
$(".tryButton330").click(function(){
$("#tryDiv330").show();
$("#stepcodeTextarea330").focus();
$("#stepcodeTextarea330").height(200);
$("#iframe330").height(0);
window.frames["iframe330"].document.write("
");
window.frames["iframe330"].document.write(decodeHtml($("textarea#stepcodeTextarea330").val()));
window.frames["iframe330"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe330"]).load(function(){
$("#iframe330").height($("#iframe330").contents().find("body").height()+showittryitheight);
});
$("#iframe330").height($("#iframe330").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor330.focus();
editor330.setSize(null, "250");
$("#rendering330").hide();
$("#rendered330").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 editor330 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea330"), {
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);
}
}
});
editor330.on("change",function(doc){
if(!binded330){
$(window).bind('beforeunload',function(){
binded330 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code330 = newCode;
$("textarea#stepcodeTextarea330").val(newCode);
if(alreadyWriteCode330!=code330){
lastModifedTime330 = new Date().getTime();
$("#rendering330").show();
$("#rendered330").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor330 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor330.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv330").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
如果是本地文件,只需把图片放在同一个目录下即可
src直接使用文件名,不需要/
图片在上级目录,则在src上加上 ../,即可访问上级目录的图片
如果是在上级目录的上级目录,则使用 ../../
src使用图片所在的绝对路径,并在前面加上file://
");
window.frames["iframe_show333"].document.write(decodeHtml($("textarea#stepcodeTextarea333").val()));
window.frames["iframe_show333"].document.close();
$(window.frames["iframe_show333"]).load(function(){
$("#iframe_show333").height($("#iframe_show333").contents().find("body").height()+showittryitheight);
});
$("#iframe_show333").height($("#iframe_show333").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<img width="200" height="200" src="http://127.0.0.1/example.gif"/>
<img width="200" height="200" src="http://127.0.0.1/example.gif"/>
");
window.frames["iframe333"].document.write(decodeHtml(code333));
window.frames["iframe333"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe333"]).load(function(){
$("#iframe333").height($("#iframe333").contents().find("body").height()+showittryitheight);
});
$("#iframe333").height($("#iframe333").contents().find("body").height()+showittryitheight);
alreadyWriteCode333 = code333;
$("#rendering333").hide();
$("#rendered333").show();
}
var tRereshRetry2DemoPanel333 = setInterval(rereshRetry2DemoPanel333,1000);
var binded333 = false;
$("textarea#stepcodeTextarea333").keyup(function(){
if(!binded333){
$(window).bind('beforeunload',function(){
binded333 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code333 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code333!=newCode){
// window.frames["iframe333"].document.write("
");
// window.frames["iframe333"].document.write(decodeHtml($("textarea#stepcodeTextarea333").val()));
// window.frames["iframe333"].document.close();
// $(window.frames["iframe333"]).load(function(){
// $("#iframe333").height($("#iframe333").contents().find("body").height()+showittryitheight);
// });
// code333 = newCode;
// }
});
$(".tryButton333").click(function(){
$("#tryDiv333").show();
$("#stepcodeTextarea333").focus();
$("#stepcodeTextarea333").height(200);
$("#iframe333").height(0);
window.frames["iframe333"].document.write("
");
window.frames["iframe333"].document.write(decodeHtml($("textarea#stepcodeTextarea333").val()));
window.frames["iframe333"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe333"]).load(function(){
$("#iframe333").height($("#iframe333").contents().find("body").height()+showittryitheight);
});
$("#iframe333").height($("#iframe333").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor333.focus();
editor333.setSize(null, "250");
$("#rendering333").hide();
$("#rendered333").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 editor333 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea333"), {
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);
}
}
});
editor333.on("change",function(doc){
if(!binded333){
$(window).bind('beforeunload',function(){
binded333 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code333 = newCode;
$("textarea#stepcodeTextarea333").val(newCode);
if(alreadyWriteCode333!=code333){
lastModifedTime333 = new Date().getTime();
$("#rendering333").show();
$("#rendered333").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor333 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor333.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv333").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
img不能够自己居中,需要放在其他能够居中的标签中实现这个效果,比如h1标签,p标签.
经常采用的手段是放在div中居中
关于div,请参考 块
");
window.frames["iframe_show335"].document.write(decodeHtml($("textarea#stepcodeTextarea335").val()));
window.frames["iframe_show335"].document.close();
$(window.frames["iframe_show335"]).load(function(){
$("#iframe_show335").height($("#iframe_show335").contents().find("body").height()+showittryitheight);
});
$("#iframe_show335").height($("#iframe_show335").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<div align="left">
<img src="http://127.0.0.1/example.gif"/>
</div>
<div align="center">
<img src="http://127.0.0.1/example.gif"/>
</div>
<div align="right">
<img src="http://127.0.0.1/example.gif"/>
</div>
<div align="left">
<img src="http://127.0.0.1/example.gif"/>
</div>
<div align="center">
<img src="http://127.0.0.1/example.gif"/>
</div>
<div align="right">
<img src="http://127.0.0.1/example.gif"/>
</div>
");
window.frames["iframe335"].document.write(decodeHtml(code335));
window.frames["iframe335"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe335"]).load(function(){
$("#iframe335").height($("#iframe335").contents().find("body").height()+showittryitheight);
});
$("#iframe335").height($("#iframe335").contents().find("body").height()+showittryitheight);
alreadyWriteCode335 = code335;
$("#rendering335").hide();
$("#rendered335").show();
}
var tRereshRetry2DemoPanel335 = setInterval(rereshRetry2DemoPanel335,1000);
var binded335 = false;
$("textarea#stepcodeTextarea335").keyup(function(){
if(!binded335){
$(window).bind('beforeunload',function(){
binded335 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code335 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code335!=newCode){
// window.frames["iframe335"].document.write("
");
// window.frames["iframe335"].document.write(decodeHtml($("textarea#stepcodeTextarea335").val()));
// window.frames["iframe335"].document.close();
// $(window.frames["iframe335"]).load(function(){
// $("#iframe335").height($("#iframe335").contents().find("body").height()+showittryitheight);
// });
// code335 = newCode;
// }
});
$(".tryButton335").click(function(){
$("#tryDiv335").show();
$("#stepcodeTextarea335").focus();
$("#stepcodeTextarea335").height(200);
$("#iframe335").height(0);
window.frames["iframe335"].document.write("
");
window.frames["iframe335"].document.write(decodeHtml($("textarea#stepcodeTextarea335").val()));
window.frames["iframe335"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe335"]).load(function(){
$("#iframe335").height($("#iframe335").contents().find("body").height()+showittryitheight);
});
$("#iframe335").height($("#iframe335").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor335.focus();
editor335.setSize(null, "250");
$("#rendering335").hide();
$("#rendered335").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 editor335 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea335"), {
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);
}
}
});
editor335.on("change",function(doc){
if(!binded335){
$(window).bind('beforeunload',function(){
binded335 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code335 = newCode;
$("textarea#stepcodeTextarea335").val(newCode);
if(alreadyWriteCode335!=code335){
lastModifedTime335 = new Date().getTime();
$("#rendering335").show();
$("#rendered335").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor335 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor335.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv335").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
如果图片不存在,默认会显示一个缺失图片,这是不友好的
所以可以加上alt属性。
当图片存在的时候,alt是不会显示的
当图片不存在的时候,alt就会出现
");
window.frames["iframe_show338"].document.write(decodeHtml($("textarea#stepcodeTextarea338").val()));
window.frames["iframe_show338"].document.close();
$(window.frames["iframe_show338"]).load(function(){
$("#iframe_show338").height($("#iframe_show338").contents().find("body").height()+showittryitheight);
});
$("#iframe_show338").height($("#iframe_show338").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<img src="http://127.0.0.1/example_not_exist.gif" />
<br/>
<img src="http://127.0.0.1/example.gif" alt="这个是一个图片" />
<br/>
<img src="http://127.0.0.1/example_not_exist.gif" alt="这个是一个图片" />
<img src="http://127.0.0.1/example_not_exist.gif" />
<br/>
<img src="http://127.0.0.1/example.gif" alt="这个是一个图片" />
<br/>
<img src="http://127.0.0.1/example_not_exist.gif" alt="这个是一个图片" />
");
window.frames["iframe338"].document.write(decodeHtml(code338));
window.frames["iframe338"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe338"]).load(function(){
$("#iframe338").height($("#iframe338").contents().find("body").height()+showittryitheight);
});
$("#iframe338").height($("#iframe338").contents().find("body").height()+showittryitheight);
alreadyWriteCode338 = code338;
$("#rendering338").hide();
$("#rendered338").show();
}
var tRereshRetry2DemoPanel338 = setInterval(rereshRetry2DemoPanel338,1000);
var binded338 = false;
$("textarea#stepcodeTextarea338").keyup(function(){
if(!binded338){
$(window).bind('beforeunload',function(){
binded338 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code338 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code338!=newCode){
// window.frames["iframe338"].document.write("
");
// window.frames["iframe338"].document.write(decodeHtml($("textarea#stepcodeTextarea338").val()));
// window.frames["iframe338"].document.close();
// $(window.frames["iframe338"]).load(function(){
// $("#iframe338").height($("#iframe338").contents().find("body").height()+showittryitheight);
// });
// code338 = newCode;
// }
});
$(".tryButton338").click(function(){
$("#tryDiv338").show();
$("#stepcodeTextarea338").focus();
$("#stepcodeTextarea338").height(200);
$("#iframe338").height(0);
window.frames["iframe338"].document.write("
");
window.frames["iframe338"].document.write(decodeHtml($("textarea#stepcodeTextarea338").val()));
window.frames["iframe338"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe338"]).load(function(){
$("#iframe338").height($("#iframe338").contents().find("body").height()+showittryitheight);
});
$("#iframe338").height($("#iframe338").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor338.focus();
editor338.setSize(null, "250");
$("#rendering338").hide();
$("#rendered338").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 editor338 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea338"), {
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);
}
}
});
editor338.on("change",function(doc){
if(!binded338){
$(window).bind('beforeunload',function(){
binded338 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code338 = newCode;
$("textarea#stepcodeTextarea338").val(newCode);
if(alreadyWriteCode338!=code338){
lastModifedTime338 = new Date().getTime();
$("#rendering338").show();
$("#rendered338").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor338 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor338.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv338").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|