|
示例
1
:
元素选择器
示例
2
:
id选择器
示例
3
:
类选择器
示例
4
:
更准确的选择
元素选择器通过标签名选择元素
在实例中,所有的p都被设置成红色
");
window.frames["iframe_show449"].document.write(decodeHtml($("textarea#stepcodeTextarea449").val()));
window.frames["iframe_show449"].document.close();
$(window.frames["iframe_show449"]).load(function(){
$("#iframe_show449").height($("#iframe_show449").contents().find("body").height()+showittryitheight);
});
$("#iframe_show449").height($("#iframe_show449").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
p{
color:red;
}
</style>
<p>p元素</p>
<p>p元素</p>
<p>p元素</p>
<style>
p{
color:red;
}
</style>
<p>p元素</p>
<p>p元素</p>
<p>p元素</p>
");
window.frames["iframe449"].document.write(decodeHtml(code449));
window.frames["iframe449"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe449"]).load(function(){
$("#iframe449").height($("#iframe449").contents().find("body").height()+showittryitheight);
});
$("#iframe449").height($("#iframe449").contents().find("body").height()+showittryitheight);
alreadyWriteCode449 = code449;
$("#rendering449").hide();
$("#rendered449").show();
}
var tRereshRetry2DemoPanel449 = setInterval(rereshRetry2DemoPanel449,1000);
var binded449 = false;
$("textarea#stepcodeTextarea449").keyup(function(){
if(!binded449){
$(window).bind('beforeunload',function(){
binded449 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code449 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code449!=newCode){
// window.frames["iframe449"].document.write("
");
// window.frames["iframe449"].document.write(decodeHtml($("textarea#stepcodeTextarea449").val()));
// window.frames["iframe449"].document.close();
// $(window.frames["iframe449"]).load(function(){
// $("#iframe449").height($("#iframe449").contents().find("body").height()+showittryitheight);
// });
// code449 = newCode;
// }
});
$(".tryButton449").click(function(){
$("#tryDiv449").show();
$("#stepcodeTextarea449").focus();
$("#stepcodeTextarea449").height(200);
$("#iframe449").height(0);
window.frames["iframe449"].document.write("
");
window.frames["iframe449"].document.write(decodeHtml($("textarea#stepcodeTextarea449").val()));
window.frames["iframe449"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe449"]).load(function(){
$("#iframe449").height($("#iframe449").contents().find("body").height()+showittryitheight);
});
$("#iframe449").height($("#iframe449").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor449.focus();
editor449.setSize(null, "250");
$("#rendering449").hide();
$("#rendered449").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 editor449 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea449"), {
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);
}
}
});
editor449.on("change",function(doc){
if(!binded449){
$(window).bind('beforeunload',function(){
binded449 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code449 = newCode;
$("textarea#stepcodeTextarea449").val(newCode);
if(alreadyWriteCode449!=code449){
lastModifedTime449 = new Date().getTime();
$("#rendering449").show();
$("#rendered449").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor449 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor449.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv449").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
通过id选择元素
注: 一个元素的id应该是唯一的。另一个元素不应该重复使用
");
window.frames["iframe_show450"].document.write(decodeHtml($("textarea#stepcodeTextarea450").val()));
window.frames["iframe_show450"].document.close();
$(window.frames["iframe_show450"]).load(function(){
$("#iframe_show450").height($("#iframe_show450").contents().find("body").height()+showittryitheight);
});
$("#iframe_show450").height($("#iframe_show450").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
p{
color:red;
}
#p1{
color:blue;
}
#p2{
color:green;
}
</style>
<p>没有id的p</p>
<p id="p1">id=p1的p</p>
<p id="p2">id=p2的p</p>
<style>
p{
color:red;
}
#p1{
color:blue;
}
#p2{
color:green;
}
</style>
<p>没有id的p</p>
<p id="p1">id=p1的p</p>
<p id="p2">id=p2的p</p>
");
window.frames["iframe450"].document.write(decodeHtml(code450));
window.frames["iframe450"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe450"]).load(function(){
$("#iframe450").height($("#iframe450").contents().find("body").height()+showittryitheight);
});
$("#iframe450").height($("#iframe450").contents().find("body").height()+showittryitheight);
alreadyWriteCode450 = code450;
$("#rendering450").hide();
$("#rendered450").show();
}
var tRereshRetry2DemoPanel450 = setInterval(rereshRetry2DemoPanel450,1000);
var binded450 = false;
$("textarea#stepcodeTextarea450").keyup(function(){
if(!binded450){
$(window).bind('beforeunload',function(){
binded450 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code450 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code450!=newCode){
// window.frames["iframe450"].document.write("
");
// window.frames["iframe450"].document.write(decodeHtml($("textarea#stepcodeTextarea450").val()));
// window.frames["iframe450"].document.close();
// $(window.frames["iframe450"]).load(function(){
// $("#iframe450").height($("#iframe450").contents().find("body").height()+showittryitheight);
// });
// code450 = newCode;
// }
});
$(".tryButton450").click(function(){
$("#tryDiv450").show();
$("#stepcodeTextarea450").focus();
$("#stepcodeTextarea450").height(200);
$("#iframe450").height(0);
window.frames["iframe450"].document.write("
");
window.frames["iframe450"].document.write(decodeHtml($("textarea#stepcodeTextarea450").val()));
window.frames["iframe450"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe450"]).load(function(){
$("#iframe450").height($("#iframe450").contents().find("body").height()+showittryitheight);
});
$("#iframe450").height($("#iframe450").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor450.focus();
editor450.setSize(null, "250");
$("#rendering450").hide();
$("#rendered450").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 editor450 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea450"), {
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);
}
}
});
editor450.on("change",function(doc){
if(!binded450){
$(window).bind('beforeunload',function(){
binded450 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code450 = newCode;
$("textarea#stepcodeTextarea450").val(newCode);
if(alreadyWriteCode450!=code450){
lastModifedTime450 = new Date().getTime();
$("#rendering450").show();
$("#rendered450").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor450 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor450.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv450").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
当需要多个元素,都使用同样的css的时候,就会使用类选择器
");
window.frames["iframe_show451"].document.write(decodeHtml($("textarea#stepcodeTextarea451").val()));
window.frames["iframe_show451"].document.close();
$(window.frames["iframe_show451"]).load(function(){
$("#iframe_show451").height($("#iframe_show451").contents().find("body").height()+showittryitheight);
});
$("#iframe_show451").height($("#iframe_show451").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
.pre{
color:blue;
}
.after{
color:green;
}
</style>
<p class="pre">前3个</p>
<p class="pre">前3个</p>
<p class="pre">前3个</p>
<p class="after">后3个</p>
<p class="after">后3个</p>
<p class="after">后3个</p>
<style>
.pre{
color:blue;
}
.after{
color:green;
}
</style>
<p class="pre">前3个</p>
<p class="pre">前3个</p>
<p class="pre">前3个</p>
<p class="after">后3个</p>
<p class="after">后3个</p>
<p class="after">后3个</p>
");
window.frames["iframe451"].document.write(decodeHtml(code451));
window.frames["iframe451"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe451"]).load(function(){
$("#iframe451").height($("#iframe451").contents().find("body").height()+showittryitheight);
});
$("#iframe451").height($("#iframe451").contents().find("body").height()+showittryitheight);
alreadyWriteCode451 = code451;
$("#rendering451").hide();
$("#rendered451").show();
}
var tRereshRetry2DemoPanel451 = setInterval(rereshRetry2DemoPanel451,1000);
var binded451 = false;
$("textarea#stepcodeTextarea451").keyup(function(){
if(!binded451){
$(window).bind('beforeunload',function(){
binded451 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code451 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code451!=newCode){
// window.frames["iframe451"].document.write("
");
// window.frames["iframe451"].document.write(decodeHtml($("textarea#stepcodeTextarea451").val()));
// window.frames["iframe451"].document.close();
// $(window.frames["iframe451"]).load(function(){
// $("#iframe451").height($("#iframe451").contents().find("body").height()+showittryitheight);
// });
// code451 = newCode;
// }
});
$(".tryButton451").click(function(){
$("#tryDiv451").show();
$("#stepcodeTextarea451").focus();
$("#stepcodeTextarea451").height(200);
$("#iframe451").height(0);
window.frames["iframe451"].document.write("
");
window.frames["iframe451"].document.write(decodeHtml($("textarea#stepcodeTextarea451").val()));
window.frames["iframe451"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe451"]).load(function(){
$("#iframe451").height($("#iframe451").contents().find("body").height()+showittryitheight);
});
$("#iframe451").height($("#iframe451").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor451.focus();
editor451.setSize(null, "250");
$("#rendering451").hide();
$("#rendered451").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 editor451 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea451"), {
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);
}
}
});
editor451.on("change",function(doc){
if(!binded451){
$(window).bind('beforeunload',function(){
binded451 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code451 = newCode;
$("textarea#stepcodeTextarea451").val(newCode);
if(alreadyWriteCode451!=code451){
lastModifedTime451 = new Date().getTime();
$("#rendering451").show();
$("#rendered451").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor451 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor451.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv451").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show466"].document.write(decodeHtml($("textarea#stepcodeTextarea466").val()));
window.frames["iframe_show466"].document.close();
$(window.frames["iframe_show466"]).load(function(){
$("#iframe_show466").height($("#iframe_show466").contents().find("body").height()+showittryitheight);
});
$("#iframe_show466").height($("#iframe_show466").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
p.blue{
color:blue;
}
</style>
<p class="blue">class=blue的p</p>
<span class="blue">class=blue的span</span>
<style>
p.blue{
color:blue;
}
</style>
<p class="blue">class=blue的p</p>
<span class="blue">class=blue的span</span>
");
window.frames["iframe466"].document.write(decodeHtml(code466));
window.frames["iframe466"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe466"]).load(function(){
$("#iframe466").height($("#iframe466").contents().find("body").height()+showittryitheight);
});
$("#iframe466").height($("#iframe466").contents().find("body").height()+showittryitheight);
alreadyWriteCode466 = code466;
$("#rendering466").hide();
$("#rendered466").show();
}
var tRereshRetry2DemoPanel466 = setInterval(rereshRetry2DemoPanel466,1000);
var binded466 = false;
$("textarea#stepcodeTextarea466").keyup(function(){
if(!binded466){
$(window).bind('beforeunload',function(){
binded466 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code466 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code466!=newCode){
// window.frames["iframe466"].document.write("
");
// window.frames["iframe466"].document.write(decodeHtml($("textarea#stepcodeTextarea466").val()));
// window.frames["iframe466"].document.close();
// $(window.frames["iframe466"]).load(function(){
// $("#iframe466").height($("#iframe466").contents().find("body").height()+showittryitheight);
// });
// code466 = newCode;
// }
});
$(".tryButton466").click(function(){
$("#tryDiv466").show();
$("#stepcodeTextarea466").focus();
$("#stepcodeTextarea466").height(200);
$("#iframe466").height(0);
window.frames["iframe466"].document.write("
");
window.frames["iframe466"].document.write(decodeHtml($("textarea#stepcodeTextarea466").val()));
window.frames["iframe466"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe466"]).load(function(){
$("#iframe466").height($("#iframe466").contents().find("body").height()+showittryitheight);
});
$("#iframe466").height($("#iframe466").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor466.focus();
editor466.setSize(null, "250");
$("#rendering466").hide();
$("#rendered466").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 editor466 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea466"), {
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);
}
}
});
editor466.on("change",function(doc){
if(!binded466){
$(window).bind('beforeunload',function(){
binded466 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code466 = newCode;
$("textarea#stepcodeTextarea466").val(newCode);
if(alreadyWriteCode466!=code466){
lastModifedTime466 = new Date().getTime();
$("#rendering466").show();
$("#rendered466").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor466 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor466.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv466").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|