|
工具版本兼容问题
Jquery有多达数十种选择器,本章节把工作中会用到的常用选择器列出来,并逐一解释。
关键字 |
简介 |
示例代码 |
$("tagName")
|
元素
|
示例代码
|
$("id")
|
id
|
示例代码
|
$("className")
|
类
|
示例代码
|
$("selector1 selector2")
|
层级
|
示例代码
|
:first :last
|
最先最后
|
示例代码
|
:odd :even
|
奇偶
|
示例代码
|
:hidden :visible
|
可见性
|
示例代码
|
[attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value]
|
属性
|
示例代码
|
:input :button :radio :checkbox :text :button :file :submit :image :reset
|
表单对象
|
示例代码
|
:enabled :disabled :checked :selected
|
表单对象属性
|
示例代码
|
this
|
当前元素
|
示例代码
|
|
练习-斑马线
|
示例代码
|
|
答案-斑马线
|
示例代码
|
示例
1
:
元素
示例
2
:
id
示例
3
:
类
示例
4
:
层级
示例
5
:
最先最后
示例
6
:
奇偶
示例
7
:
可见性
示例
8
:
属性
示例
9
:
表单对象
示例
10
:
表单对象属性
示例
11
:
当前元素
示例
12
:
练习-斑马线
示例
13
:
答案-斑马线
$("tagName")
根据 标签名 选择所有该标签的元素
");
window.frames["iframe_show968"].document.write(decodeHtml($("textarea#stepcodeTextarea968").val()));
window.frames["iframe_show968"].document.close();
$(window.frames["iframe_show968"]).load(function(){
$("#iframe_show968").height($("#iframe_show968").contents().find("body").height()+showittryitheight);
});
$("#iframe_show968").height($("#iframe_show968").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div").addClass("pink");
});
});
</script>
<button id="b1">给所有的div元素增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div >
Hello JQuery
</div>
<div >
Hello JQuery
</div>
<div >
Hello JQuery
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div").addClass("pink");
});
});
</script>
<button id="b1">给所有的div元素增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div >
Hello JQuery
</div>
<div >
Hello JQuery
</div>
<div >
Hello JQuery
</div>
");
window.frames["iframe968"].document.write(decodeHtml(code968));
window.frames["iframe968"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe968"]).load(function(){
$("#iframe968").height($("#iframe968").contents().find("body").height()+showittryitheight);
});
$("#iframe968").height($("#iframe968").contents().find("body").height()+showittryitheight);
alreadyWriteCode968 = code968;
$("#rendering968").hide();
$("#rendered968").show();
}
var tRereshRetry2DemoPanel968 = setInterval(rereshRetry2DemoPanel968,1000);
var binded968 = false;
$("textarea#stepcodeTextarea968").keyup(function(){
if(!binded968){
$(window).bind('beforeunload',function(){
binded968 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code968 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code968!=newCode){
// window.frames["iframe968"].document.write("
");
// window.frames["iframe968"].document.write(decodeHtml($("textarea#stepcodeTextarea968").val()));
// window.frames["iframe968"].document.close();
// $(window.frames["iframe968"]).load(function(){
// $("#iframe968").height($("#iframe968").contents().find("body").height()+showittryitheight);
// });
// code968 = newCode;
// }
});
$(".tryButton968").click(function(){
$("#tryDiv968").show();
$("#stepcodeTextarea968").focus();
$("#stepcodeTextarea968").height(200);
$("#iframe968").height(0);
window.frames["iframe968"].document.write("
");
window.frames["iframe968"].document.write(decodeHtml($("textarea#stepcodeTextarea968").val()));
window.frames["iframe968"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe968"]).load(function(){
$("#iframe968").height($("#iframe968").contents().find("body").height()+showittryitheight);
});
$("#iframe968").height($("#iframe968").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor968.focus();
editor968.setSize(null, "250");
$("#rendering968").hide();
$("#rendered968").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 editor968 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea968"), {
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);
}
}
});
editor968.on("change",function(doc){
if(!binded968){
$(window).bind('beforeunload',function(){
binded968 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code968 = newCode;
$("textarea#stepcodeTextarea968").val(newCode);
if(alreadyWriteCode968!=code968){
lastModifedTime968 = new Date().getTime();
$("#rendering968").show();
$("#rendered968").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor968 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor968.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv968").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$("#id") 根据 id 选择元素 id应该是唯一的,如果id重复,则只会选择第一个。
");
window.frames["iframe_show969"].document.write(decodeHtml($("textarea#stepcodeTextarea969").val()));
window.frames["iframe_show969"].document.close();
$(window.frames["iframe_show969"]).load(function(){
$("#iframe_show969").height($("#iframe_show969").contents().find("body").height()+showittryitheight);
});
$("#iframe_show969").height($("#iframe_show969").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("#d1").addClass("pink");
});
});
</script>
<button id="b1">给id=d1的div增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div id="d1">
Hello JQuery
</div>
<div id="d2" >
Hello JQuery
</div>
<div id="d3">
Hello JQuery
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("#d1").addClass("pink");
});
});
</script>
<button id="b1">给id=d1的div增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div id="d1">
Hello JQuery
</div>
<div id="d2" >
Hello JQuery
</div>
<div id="d3">
Hello JQuery
</div>
");
window.frames["iframe969"].document.write(decodeHtml(code969));
window.frames["iframe969"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe969"]).load(function(){
$("#iframe969").height($("#iframe969").contents().find("body").height()+showittryitheight);
});
$("#iframe969").height($("#iframe969").contents().find("body").height()+showittryitheight);
alreadyWriteCode969 = code969;
$("#rendering969").hide();
$("#rendered969").show();
}
var tRereshRetry2DemoPanel969 = setInterval(rereshRetry2DemoPanel969,1000);
var binded969 = false;
$("textarea#stepcodeTextarea969").keyup(function(){
if(!binded969){
$(window).bind('beforeunload',function(){
binded969 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code969 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code969!=newCode){
// window.frames["iframe969"].document.write("
");
// window.frames["iframe969"].document.write(decodeHtml($("textarea#stepcodeTextarea969").val()));
// window.frames["iframe969"].document.close();
// $(window.frames["iframe969"]).load(function(){
// $("#iframe969").height($("#iframe969").contents().find("body").height()+showittryitheight);
// });
// code969 = newCode;
// }
});
$(".tryButton969").click(function(){
$("#tryDiv969").show();
$("#stepcodeTextarea969").focus();
$("#stepcodeTextarea969").height(200);
$("#iframe969").height(0);
window.frames["iframe969"].document.write("
");
window.frames["iframe969"].document.write(decodeHtml($("textarea#stepcodeTextarea969").val()));
window.frames["iframe969"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe969"]).load(function(){
$("#iframe969").height($("#iframe969").contents().find("body").height()+showittryitheight);
});
$("#iframe969").height($("#iframe969").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor969.focus();
editor969.setSize(null, "250");
$("#rendering969").hide();
$("#rendered969").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 editor969 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea969"), {
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);
}
}
});
editor969.on("change",function(doc){
if(!binded969){
$(window).bind('beforeunload',function(){
binded969 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code969 = newCode;
$("textarea#stepcodeTextarea969").val(newCode);
if(alreadyWriteCode969!=code969){
lastModifedTime969 = new Date().getTime();
$("#rendering969").show();
$("#rendered969").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor969 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor969.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv969").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$(".className")
根据 class 选择元素
");
window.frames["iframe_show970"].document.write(decodeHtml($("textarea#stepcodeTextarea970").val()));
window.frames["iframe_show970"].document.close();
$(window.frames["iframe_show970"]).load(function(){
$("#iframe_show970").height($("#iframe_show970").contents().find("body").height()+showittryitheight);
});
$("#iframe_show970").height($("#iframe_show970").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$(".d").addClass("pink");
});
});
</script>
<button id="b1">给class='d'的div增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div class="d">
Hello JQuery
</div>
<div class="d" >
Hello JQuery
</div>
<div >
Hello JQuery
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$(".d").addClass("pink");
});
});
</script>
<button id="b1">给class='d'的div增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div class="d">
Hello JQuery
</div>
<div class="d" >
Hello JQuery
</div>
<div >
Hello JQuery
</div>
");
window.frames["iframe970"].document.write(decodeHtml(code970));
window.frames["iframe970"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe970"]).load(function(){
$("#iframe970").height($("#iframe970").contents().find("body").height()+showittryitheight);
});
$("#iframe970").height($("#iframe970").contents().find("body").height()+showittryitheight);
alreadyWriteCode970 = code970;
$("#rendering970").hide();
$("#rendered970").show();
}
var tRereshRetry2DemoPanel970 = setInterval(rereshRetry2DemoPanel970,1000);
var binded970 = false;
$("textarea#stepcodeTextarea970").keyup(function(){
if(!binded970){
$(window).bind('beforeunload',function(){
binded970 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code970 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code970!=newCode){
// window.frames["iframe970"].document.write("
");
// window.frames["iframe970"].document.write(decodeHtml($("textarea#stepcodeTextarea970").val()));
// window.frames["iframe970"].document.close();
// $(window.frames["iframe970"]).load(function(){
// $("#iframe970").height($("#iframe970").contents().find("body").height()+showittryitheight);
// });
// code970 = newCode;
// }
});
$(".tryButton970").click(function(){
$("#tryDiv970").show();
$("#stepcodeTextarea970").focus();
$("#stepcodeTextarea970").height(200);
$("#iframe970").height(0);
window.frames["iframe970"].document.write("
");
window.frames["iframe970"].document.write(decodeHtml($("textarea#stepcodeTextarea970").val()));
window.frames["iframe970"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe970"]).load(function(){
$("#iframe970").height($("#iframe970").contents().find("body").height()+showittryitheight);
});
$("#iframe970").height($("#iframe970").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor970.focus();
editor970.setSize(null, "250");
$("#rendering970").hide();
$("#rendered970").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 editor970 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea970"), {
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);
}
}
});
editor970.on("change",function(doc){
if(!binded970){
$(window).bind('beforeunload',function(){
binded970 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code970 = newCode;
$("textarea#stepcodeTextarea970").val(newCode);
if(alreadyWriteCode970!=code970){
lastModifedTime970 = new Date().getTime();
$("#rendering970").show();
$("#rendered970").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor970 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor970.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv970").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$("selector1 selector2")
选择 selector1下的selector2元素 。
在本例中 选择id=d3的div下的span元素
");
window.frames["iframe_show971"].document.write(decodeHtml($("textarea#stepcodeTextarea971").val()));
window.frames["iframe_show971"].document.close();
$(window.frames["iframe_show971"]).load(function(){
$("#iframe_show971").height($("#iframe_show971").contents().find("body").height()+showittryitheight);
});
$("#iframe_show971").height($("#iframe_show971").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div#d3 span").addClass("pink");
});
});
</script>
<button id="b1">给id='d3'的div 下的 span 增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div class="d">
<span>Hello JQuery</span>
</div>
<div class="d" >
<span>Hello JQuery</span>
</div>
<div id="d3" >
<span>Hello JQuery</span>
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div#d3 span").addClass("pink");
});
});
</script>
<button id="b1">给id='d3'的div 下的 span 增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div class="d">
<span>Hello JQuery</span>
</div>
<div class="d" >
<span>Hello JQuery</span>
</div>
<div id="d3" >
<span>Hello JQuery</span>
</div>
");
window.frames["iframe971"].document.write(decodeHtml(code971));
window.frames["iframe971"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe971"]).load(function(){
$("#iframe971").height($("#iframe971").contents().find("body").height()+showittryitheight);
});
$("#iframe971").height($("#iframe971").contents().find("body").height()+showittryitheight);
alreadyWriteCode971 = code971;
$("#rendering971").hide();
$("#rendered971").show();
}
var tRereshRetry2DemoPanel971 = setInterval(rereshRetry2DemoPanel971,1000);
var binded971 = false;
$("textarea#stepcodeTextarea971").keyup(function(){
if(!binded971){
$(window).bind('beforeunload',function(){
binded971 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code971 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code971!=newCode){
// window.frames["iframe971"].document.write("
");
// window.frames["iframe971"].document.write(decodeHtml($("textarea#stepcodeTextarea971").val()));
// window.frames["iframe971"].document.close();
// $(window.frames["iframe971"]).load(function(){
// $("#iframe971").height($("#iframe971").contents().find("body").height()+showittryitheight);
// });
// code971 = newCode;
// }
});
$(".tryButton971").click(function(){
$("#tryDiv971").show();
$("#stepcodeTextarea971").focus();
$("#stepcodeTextarea971").height(200);
$("#iframe971").height(0);
window.frames["iframe971"].document.write("
");
window.frames["iframe971"].document.write(decodeHtml($("textarea#stepcodeTextarea971").val()));
window.frames["iframe971"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe971"]).load(function(){
$("#iframe971").height($("#iframe971").contents().find("body").height()+showittryitheight);
});
$("#iframe971").height($("#iframe971").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor971.focus();
editor971.setSize(null, "250");
$("#rendering971").hide();
$("#rendered971").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 editor971 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea971"), {
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);
}
}
});
editor971.on("change",function(doc){
if(!binded971){
$(window).bind('beforeunload',function(){
binded971 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code971 = newCode;
$("textarea#stepcodeTextarea971").val(newCode);
if(alreadyWriteCode971!=code971){
lastModifedTime971 = new Date().getTime();
$("#rendering971").show();
$("#rendered971").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor971 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor971.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv971").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$(selector:first) 满足选择器条件的第一个元素
$(selector:last) 满足选择器条件的最后一个元素
");
window.frames["iframe_show972"].document.write(decodeHtml($("textarea#stepcodeTextarea972").val()));
window.frames["iframe_show972"].document.close();
$(window.frames["iframe_show972"]).load(function(){
$("#iframe_show972").height($("#iframe_show972").contents().find("body").height()+showittryitheight);
});
$("#iframe_show972").height($("#iframe_show972").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div:first").addClass("pink");
});
$("#b2").click(function(){
$("div:last").addClass("pink");
});
});
</script>
<button id="b1">第一个增加背景色</button>
<button id="b2">最后一个增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div>
<span>Hello JQuery</span>
</div>
<div >
<span>Hello JQuery</span>
</div>
<div >
<span>Hello JQuery</span>
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div:first").addClass("pink");
});
$("#b2").click(function(){
$("div:last").addClass("pink");
});
});
</script>
<button id="b1">第一个增加背景色</button>
<button id="b2">最后一个增加背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div>
<span>Hello JQuery</span>
</div>
<div >
<span>Hello JQuery</span>
</div>
<div >
<span>Hello JQuery</span>
</div>
");
window.frames["iframe972"].document.write(decodeHtml(code972));
window.frames["iframe972"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe972"]).load(function(){
$("#iframe972").height($("#iframe972").contents().find("body").height()+showittryitheight);
});
$("#iframe972").height($("#iframe972").contents().find("body").height()+showittryitheight);
alreadyWriteCode972 = code972;
$("#rendering972").hide();
$("#rendered972").show();
}
var tRereshRetry2DemoPanel972 = setInterval(rereshRetry2DemoPanel972,1000);
var binded972 = false;
$("textarea#stepcodeTextarea972").keyup(function(){
if(!binded972){
$(window).bind('beforeunload',function(){
binded972 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code972 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code972!=newCode){
// window.frames["iframe972"].document.write("
");
// window.frames["iframe972"].document.write(decodeHtml($("textarea#stepcodeTextarea972").val()));
// window.frames["iframe972"].document.close();
// $(window.frames["iframe972"]).load(function(){
// $("#iframe972").height($("#iframe972").contents().find("body").height()+showittryitheight);
// });
// code972 = newCode;
// }
});
$(".tryButton972").click(function(){
$("#tryDiv972").show();
$("#stepcodeTextarea972").focus();
$("#stepcodeTextarea972").height(200);
$("#iframe972").height(0);
window.frames["iframe972"].document.write("
");
window.frames["iframe972"].document.write(decodeHtml($("textarea#stepcodeTextarea972").val()));
window.frames["iframe972"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe972"]).load(function(){
$("#iframe972").height($("#iframe972").contents().find("body").height()+showittryitheight);
});
$("#iframe972").height($("#iframe972").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor972.focus();
editor972.setSize(null, "250");
$("#rendering972").hide();
$("#rendered972").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 editor972 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea972"), {
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);
}
}
});
editor972.on("change",function(doc){
if(!binded972){
$(window).bind('beforeunload',function(){
binded972 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code972 = newCode;
$("textarea#stepcodeTextarea972").val(newCode);
if(alreadyWriteCode972!=code972){
lastModifedTime972 = new Date().getTime();
$("#rendering972").show();
$("#rendered972").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor972 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor972.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv972").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$(selector:odd) 满足选择器条件的奇数元素
$(selector:even) 满足选择器条件的偶数元素
因为是基零的,所以第一排的下标其实是0(是偶数)
");
window.frames["iframe_show973"].document.write(decodeHtml($("textarea#stepcodeTextarea973").val()));
window.frames["iframe_show973"].document.close();
$(window.frames["iframe_show973"]).load(function(){
$("#iframe_show973").height($("#iframe_show973").contents().find("body").height()+showittryitheight);
});
$("#iframe_show973").height($("#iframe_show973").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div:odd").toggleClass("pink");
});
$("#b2").click(function(){
$("div:even").toggleClass("green");
});
});
</script>
<button id="b1">切换奇数背景色</button>
<button id="b2">切换偶数背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
.green{
background-color:green;
}
</style>
<div>
<span>Hello JQuery 0</span>
</div>
<div>
<span>Hello JQuery 1</span>
</div>
<div >
<span>Hello JQuery 2</span>
</div>
<div >
<span>Hello JQuery 3</span>
</div>
<div >
<span>Hello JQuery 4</span>
</div>
</div>
<div >
<span>Hello JQuery 5</span>
</div>
<div >
<span>Hello JQuery 6</span>
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div:odd").toggleClass("pink");
});
$("#b2").click(function(){
$("div:even").toggleClass("green");
});
});
</script>
<button id="b1">切换奇数背景色</button>
<button id="b2">切换偶数背景色</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
.green{
background-color:green;
}
</style>
<div>
<span>Hello JQuery 0</span>
</div>
<div>
<span>Hello JQuery 1</span>
</div>
<div >
<span>Hello JQuery 2</span>
</div>
<div >
<span>Hello JQuery 3</span>
</div>
<div >
<span>Hello JQuery 4</span>
</div>
</div>
<div >
<span>Hello JQuery 5</span>
</div>
<div >
<span>Hello JQuery 6</span>
</div>
");
window.frames["iframe973"].document.write(decodeHtml(code973));
window.frames["iframe973"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe973"]).load(function(){
$("#iframe973").height($("#iframe973").contents().find("body").height()+showittryitheight);
});
$("#iframe973").height($("#iframe973").contents().find("body").height()+showittryitheight);
alreadyWriteCode973 = code973;
$("#rendering973").hide();
$("#rendered973").show();
}
var tRereshRetry2DemoPanel973 = setInterval(rereshRetry2DemoPanel973,1000);
var binded973 = false;
$("textarea#stepcodeTextarea973").keyup(function(){
if(!binded973){
$(window).bind('beforeunload',function(){
binded973 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code973 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code973!=newCode){
// window.frames["iframe973"].document.write("
");
// window.frames["iframe973"].document.write(decodeHtml($("textarea#stepcodeTextarea973").val()));
// window.frames["iframe973"].document.close();
// $(window.frames["iframe973"]).load(function(){
// $("#iframe973").height($("#iframe973").contents().find("body").height()+showittryitheight);
// });
// code973 = newCode;
// }
});
$(".tryButton973").click(function(){
$("#tryDiv973").show();
$("#stepcodeTextarea973").focus();
$("#stepcodeTextarea973").height(200);
$("#iframe973").height(0);
window.frames["iframe973"].document.write("
");
window.frames["iframe973"].document.write(decodeHtml($("textarea#stepcodeTextarea973").val()));
window.frames["iframe973"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe973"]).load(function(){
$("#iframe973").height($("#iframe973").contents().find("body").height()+showittryitheight);
});
$("#iframe973").height($("#iframe973").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor973.focus();
editor973.setSize(null, "250");
$("#rendering973").hide();
$("#rendered973").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 editor973 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea973"), {
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);
}
}
});
editor973.on("change",function(doc){
if(!binded973){
$(window).bind('beforeunload',function(){
binded973 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code973 = newCode;
$("textarea#stepcodeTextarea973").val(newCode);
if(alreadyWriteCode973!=code973){
lastModifedTime973 = new Date().getTime();
$("#rendering973").show();
$("#rendered973").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor973 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor973.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv973").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$(selector:hidden) 满足选择器条件的不可见的元素 $(selector:visible) 满足选择器条件的可见的元素 注; div:visible 和div :visible(有空格)是不同的意思 div:visible 表示选中可见的div div :visible(有空格) 表示选中div下可见的元素
");
window.frames["iframe_show975"].document.write(decodeHtml($("textarea#stepcodeTextarea975").val()));
window.frames["iframe_show975"].document.close();
$(window.frames["iframe_show975"]).load(function(){
$("#iframe_show975").height($("#iframe_show975").contents().find("body").height()+showittryitheight);
});
$("#iframe_show975").height($("#iframe_show975").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div:visible").hide();
});
$("#b2").click(function(){
$("div:hidden").show();
});
});
</script>
<button id="b1">隐藏可见的</button>
<button id="b2">显示不可见的</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div>
<span>Hello JQuery 1</span>
</div>
<div >
<span>Hello JQuery 2</span>
</div>
<div >
<span>Hello JQuery 3</span>
</div>
<div >
<span >Hello JQuery 4</span>
</div>
</div>
<div >
<span>Hello JQuery 5</span>
</div>
<div >
<span>Hello JQuery 6</span>
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div:visible").hide();
});
$("#b2").click(function(){
$("div:hidden").show();
});
});
</script>
<button id="b1">隐藏可见的</button>
<button id="b2">显示不可见的</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
</style>
<div>
<span>Hello JQuery 1</span>
</div>
<div >
<span>Hello JQuery 2</span>
</div>
<div >
<span>Hello JQuery 3</span>
</div>
<div >
<span >Hello JQuery 4</span>
</div>
</div>
<div >
<span>Hello JQuery 5</span>
</div>
<div >
<span>Hello JQuery 6</span>
</div>
");
window.frames["iframe975"].document.write(decodeHtml(code975));
window.frames["iframe975"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe975"]).load(function(){
$("#iframe975").height($("#iframe975").contents().find("body").height()+showittryitheight);
});
$("#iframe975").height($("#iframe975").contents().find("body").height()+showittryitheight);
alreadyWriteCode975 = code975;
$("#rendering975").hide();
$("#rendered975").show();
}
var tRereshRetry2DemoPanel975 = setInterval(rereshRetry2DemoPanel975,1000);
var binded975 = false;
$("textarea#stepcodeTextarea975").keyup(function(){
if(!binded975){
$(window).bind('beforeunload',function(){
binded975 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code975 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code975!=newCode){
// window.frames["iframe975"].document.write("
");
// window.frames["iframe975"].document.write(decodeHtml($("textarea#stepcodeTextarea975").val()));
// window.frames["iframe975"].document.close();
// $(window.frames["iframe975"]).load(function(){
// $("#iframe975").height($("#iframe975").contents().find("body").height()+showittryitheight);
// });
// code975 = newCode;
// }
});
$(".tryButton975").click(function(){
$("#tryDiv975").show();
$("#stepcodeTextarea975").focus();
$("#stepcodeTextarea975").height(200);
$("#iframe975").height(0);
window.frames["iframe975"].document.write("
");
window.frames["iframe975"].document.write(decodeHtml($("textarea#stepcodeTextarea975").val()));
window.frames["iframe975"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe975"]).load(function(){
$("#iframe975").height($("#iframe975").contents().find("body").height()+showittryitheight);
});
$("#iframe975").height($("#iframe975").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor975.focus();
editor975.setSize(null, "250");
$("#rendering975").hide();
$("#rendered975").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 editor975 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea975"), {
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);
}
}
});
editor975.on("change",function(doc){
if(!binded975){
$(window).bind('beforeunload',function(){
binded975 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code975 = newCode;
$("textarea#stepcodeTextarea975").val(newCode);
if(alreadyWriteCode975!=code975){
lastModifedTime975 = new Date().getTime();
$("#rendering975").show();
$("#rendered975").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor975 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor975.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv975").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
$(selector[attribute]) 满足选择器条件的有某属性的元素 $(selector[attribute=value]) 满足选择器条件的属性等于value的元素 $(selector[attribute!=value]) 满足选择器条件的属性不等于value的元素 $(selector[attribute^=value]) 满足选择器条件的属性以value开头的元素 $(selector[attribute$=value]) 满足选择器条件的属性以value结尾的元素 $(selector[attribute*=value]) 满足选择器条件的属性包含value的元素
注: 一般不要使用[class=className] 而应该使用.className 因为使用$("[class='className']") .toggleClass("anotherClassName") 会导致class变成className anotherClassName,再次 使用 [class=className] 就无法选中了 而.className没有这个问题。
");
window.frames["iframe_show976"].document.write(decodeHtml($("textarea#stepcodeTextarea976").val()));
window.frames["iframe_show976"].document.close();
$(window.frames["iframe_show976"]).load(function(){
$("#iframe_show976").height($("#iframe_show976").contents().find("body").height()+showittryitheight);
});
$("#iframe_show976").height($("#iframe_show976").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div[id]").toggleClass("border");
});
$("#b2").click(function(){
$("div[id='pink']").toggleClass("border");
});
$("#b3").click(function(){
$("div[id!='pink']").toggleClass("border");
});
$("#b4").click(function(){
$("div[id^='p']").toggleClass("border");
});
$("#b5").click(function(){
$("div[id$='k']").toggleClass("border");
});
$("#b6").click(function(){
$("div[id*='ee']").toggleClass("border");
});
});
</script>
<button id="b1">给有id属性的div切换边框</button>
<button id="b2">给id=pink的div切换边框</button>
<button id="b3">给有id!=pink属性的div切换边框</button>
<button id="b4">给有id以p开头的div切换边框</button>
<button id="b5">给有id以k结尾的div切换边框</button>
<button id="b6">给有id包含ee的div切换边框</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
.green{
background-color:green;
}
.border{
border: 1px blue solid;
}
button{
margin-top:10px;
display:block;
}
div{
margin:10px;
}
</style>
<div id="pink">
id=pink的div
</div>
<div id="green">
id=green的div
</div>
<div >
没有id的div
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("div[id]").toggleClass("border");
});
$("#b2").click(function(){
$("div[id='pink']").toggleClass("border");
});
$("#b3").click(function(){
$("div[id!='pink']").toggleClass("border");
});
$("#b4").click(function(){
$("div[id^='p']").toggleClass("border");
});
$("#b5").click(function(){
$("div[id$='k']").toggleClass("border");
});
$("#b6").click(function(){
$("div[id*='ee']").toggleClass("border");
});
});
</script>
<button id="b1">给有id属性的div切换边框</button>
<button id="b2">给id=pink的div切换边框</button>
<button id="b3">给有id!=pink属性的div切换边框</button>
<button id="b4">给有id以p开头的div切换边框</button>
<button id="b5">给有id以k结尾的div切换边框</button>
<button id="b6">给有id包含ee的div切换边框</button>
<br>
<br>
<style>
.pink{
background-color:pink;
}
.green{
background-color:green;
}
.border{
border: 1px blue solid;
}
button{
margin-top:10px;
display:block;
}
div{
margin:10px;
}
</style>
<div id="pink">
id=pink的div
</div>
<div id="green">
id=green的div
</div>
<div >
没有id的div
</div>
");
window.frames["iframe976"].document.write(decodeHtml(code976));
window.frames["iframe976"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe976"]).load(function(){
$("#iframe976").height($("#iframe976").contents().find("body").height()+showittryitheight);
});
$("#iframe976").height($("#iframe976").contents().find("body").height()+showittryitheight);
alreadyWriteCode976 = code976;
$("#rendering976").hide();
$("#rendered976").show();
}
var tRereshRetry2DemoPanel976 = setInterval(rereshRetry2DemoPanel976,1000);
var binded976 = false;
$("textarea#stepcodeTextarea976").keyup(function(){
if(!binded976){
$(window).bind('beforeunload',function(){
binded976 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code976 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code976!=newCode){
// window.frames["iframe976"].document.write("
");
// window.frames["iframe976"].document.write(decodeHtml($("textarea#stepcodeTextarea976").val()));
// window.frames["iframe976"].document.close();
// $(window.frames["iframe976"]).load(function(){
// $("#iframe976").height($("#iframe976").contents().find("body").height()+showittryitheight);
// });
// code976 = newCode;
// }
});
$(".tryButton976").click(function(){
$("#tryDiv976").show();
$("#stepcodeTextarea976").focus();
$("#stepcodeTextarea976").height(200);
$("#iframe976").height(0);
window.frames["iframe976"].document.write("
");
window.frames["iframe976"].document.write(decodeHtml($("textarea#stepcodeTextarea976").val()));
window.frames["iframe976"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe976"]).load(function(){
$("#iframe976").height($("#iframe976").contents().find("body").height()+showittryitheight);
});
$("#iframe976").height($("#iframe976").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor976.focus();
editor976.setSize(null, "250");
$("#rendering976").hide();
$("#rendered976").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 editor976 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea976"), {
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);
}
}
});
editor976.on("change",function(doc){
if(!binded976){
$(window).bind('beforeunload',function(){
binded976 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code976 = newCode;
$("textarea#stepcodeTextarea976").val(newCode);
if(alreadyWriteCode976!=code976){
lastModifedTime976 = new Date().getTime();
$("#rendering976").show();
$("#rendered976").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor976 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor976.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv976").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
表单对象选择器 指的是选中form下会出现的输入元素 :input 会选择所有的输入元素,不仅仅是input标签开始的那些,还包括 textarea, select和 button:button 会选择 type=button的input元素和 button元素 :radio 会选择 单选框:checkbox会选择 复选框:text会选择 文本框,但是不会选择文本域 :submit会选择 提交按钮:image会选择 图片型提交按钮:reset会选择 重置按钮注意: 第7行 $("td[rowspan!=13] "+value).toggle(500);
$("td[rowspan!=13] 后面有一个空格,表示层级选择器,如果没有就会出错 toggle(500) 表示在显示与隐藏之间来回切换,生效时间是500毫秒 注: :submit会把<button>元素选中,因为在一些浏览器中,<button>元素的type默认值是submit,所以会选中它。 关于这个问题,请移步参考: 使用button元素提交数据
");
window.frames["iframe_show977"].document.write(decodeHtml($("textarea#stepcodeTextarea977").val()));
window.frames["iframe_show977"].document.close();
$(window.frames["iframe_show977"]).load(function(){
$("#iframe_show977").height($("#iframe_show977").contents().find("body").height()+showittryitheight);
});
$("#iframe_show977").height($("#iframe_show977").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$(".b").click(function(){
var value = $(this).val();
$("td[rowspan!=13] "+value).toggle(500);
});
});
</script>
<style>
table{
border-collapse:collapse;
table-layout:fixed;
width:80%;
}
table td{
border-bottom: 1px solid #ddd;
padding-bottom: 5px;
padding-top: 5px;
}
div button{
display:block;
}
</style>
<table>
<tr>
<td rowspan="13" valign="top" width="150px">
<div >
<button value=":input" class="b">切换所有的:input</button>
<button value=":button" class="b">切换:button</button>
<button value=":radio" class="b">切换:radio</button>
<button value=":checkbox" class="b">切换:checkbox</button>
<button value=":text" class="b">切换:text</button>
<button value=":password" class="b">切换:password</button>
<button value=":file" class="b">切换:file</button>
<button value=":submit" class="b">切换:submit</button>
<button value=":image" class="b">切换:image</button>
<button value=":reset" class="b">切换:reset</button>
</div>
</td>
<td width="120px">说明</td>
<td width="120px">表单对象</td>
<td width="">示例</td>
</tr>
<tr>
<td >input按钮</td>
<td >:button</td>
<td><input type="button" value="input按钮"/></td>
</tr>
<tr>
<td>button按钮</td>
<td >:button</td>
<td><button>Button按钮</button></td>
</tr>
<tr>
<td>单选框</td>
<td >:radio</td>
<td><input type="radio" ></td>
</tr>
<tr>
<td>复选框</td>
<td >:checkbox</td>
<td><input type="checkbox" ></td>
</tr>
<tr>
<td>文本框</td>
<td >:text</td>
<td><input type="text" /></td>
</tr>
<tr>
<td>文本域</td>
<td ></td>
<td><textarea></textarea></td>
</tr>
<tr>
<td>密码框</td>
<td >:password</td>
<td><input type="password" /></td>
</tr>
<tr>
<td>下拉框</td>
<td ></td>
<td><select><option>Option</option></select></td>
</tr>
<tr>
<td>文件上传</td>
<td >:file</td>
<td> <input type="file" /></td>
</tr>
<tr>
<td>提交按钮</td>
<td >:submit</td>
<td><input type="submit" /></td>
</tr>
<tr>
<td>图片型提交按钮</td>
<td >:image</td>
<td><input type="image" src="http://127.0.0.1/example.gif" /></td>
</tr>
<tr>
<td>重置按钮</td>
<td >:reset</td>
<td><input type="reset" /></td>
</tr>
</table>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$(".b").click(function(){
var value = $(this).val();
$("td[rowspan!=13] "+value).toggle(500);
});
});
</script>
<style>
table{
border-collapse:collapse;
table-layout:fixed;
width:80%;
}
table td{
border-bottom: 1px solid #ddd;
padding-bottom: 5px;
padding-top: 5px;
}
div button{
display:block;
}
</style>
<table>
<tr>
<td rowspan="13" valign="top" width="150px">
<div >
<button value=":input" class="b">切换所有的:input</button>
<button value=":button" class="b">切换:button</button>
<button value=":radio" class="b">切换:radio</button>
<button value=":checkbox" class="b">切换:checkbox</button>
<button value=":text" class="b">切换:text</button>
<button value=":password" class="b">切换:password</button>
<button value=":file" class="b">切换:file</button>
<button value=":submit" class="b">切换:submit</button>
<button value=":image" class="b">切换:image</button>
<button value=":reset" class="b">切换:reset</button>
</div>
</td>
<td width="120px">说明</td>
<td width="120px">表单对象</td>
<td width="">示例</td>
</tr>
<tr>
<td >input按钮</td>
<td >:button</td>
<td><input type="button" value="input按钮"/></td>
</tr>
<tr>
<td>button按钮</td>
<td >:button</td>
<td><button>Button按钮</button></td>
</tr>
<tr>
<td>单选框</td>
<td >:radio</td>
<td><input type="radio" ></td>
</tr>
<tr>
<td>复选框</td>
<td >:checkbox</td>
<td><input type="checkbox" ></td>
</tr>
<tr>
<td>文本框</td>
<td >:text</td>
<td><input type="text" /></td>
</tr>
<tr>
<td>文本域</td>
<td ></td>
<td><textarea></textarea></td>
</tr>
<tr>
<td>密码框</td>
<td >:password</td>
<td><input type="password" /></td>
</tr>
<tr>
<td>下拉框</td>
<td ></td>
<td><select><option>Option</option></select></td>
</tr>
<tr>
<td>文件上传</td>
<td >:file</td>
<td> <input type="file" /></td>
</tr>
<tr>
<td>提交按钮</td>
<td >:submit</td>
<td><input type="submit" /></td>
</tr>
<tr>
<td>图片型提交按钮</td>
<td >:image</td>
<td><input type="image" src="http://127.0.0.1/example.gif" /></td>
</tr>
<tr>
<td>重置按钮</td>
<td >:reset</td>
<td><input type="reset" /></td>
</tr>
</table>
");
window.frames["iframe977"].document.write(decodeHtml(code977));
window.frames["iframe977"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe977"]).load(function(){
$("#iframe977").height($("#iframe977").contents().find("body").height()+showittryitheight);
});
$("#iframe977").height($("#iframe977").contents().find("body").height()+showittryitheight);
alreadyWriteCode977 = code977;
$("#rendering977").hide();
$("#rendered977").show();
}
var tRereshRetry2DemoPanel977 = setInterval(rereshRetry2DemoPanel977,1000);
var binded977 = false;
$("textarea#stepcodeTextarea977").keyup(function(){
if(!binded977){
$(window).bind('beforeunload',function(){
binded977 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code977 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code977!=newCode){
// window.frames["iframe977"].document.write("
");
// window.frames["iframe977"].document.write(decodeHtml($("textarea#stepcodeTextarea977").val()));
// window.frames["iframe977"].document.close();
// $(window.frames["iframe977"]).load(function(){
// $("#iframe977").height($("#iframe977").contents().find("body").height()+showittryitheight);
// });
// code977 = newCode;
// }
});
$(".tryButton977").click(function(){
$("#tryDiv977").show();
$("#stepcodeTextarea977").focus();
$("#stepcodeTextarea977").height(200);
$("#iframe977").height(0);
window.frames["iframe977"].document.write("
");
window.frames["iframe977"].document.write(decodeHtml($("textarea#stepcodeTextarea977").val()));
window.frames["iframe977"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe977"]).load(function(){
$("#iframe977").height($("#iframe977").contents().find("body").height()+showittryitheight);
});
$("#iframe977").height($("#iframe977").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor977.focus();
editor977.setSize(null, "250");
$("#rendering977").hide();
$("#rendered977").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 editor977 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea977"), {
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);
}
}
});
editor977.on("change",function(doc){
if(!binded977){
$(window).bind('beforeunload',function(){
binded977 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code977 = newCode;
$("textarea#stepcodeTextarea977").val(newCode);
if(alreadyWriteCode977!=code977){
lastModifedTime977 = new Date().getTime();
$("#rendering977").show();
$("#rendered977").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor977 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor977.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv977").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
:enabled会选择可用的输入元素 注:输入元素的默认状态都是可用
:disabled会选择不可用的输入元素
:checked会选择被选中的单选框和复选框 注: checked在部分浏览器上(火狐,chrome)也可以选中selected的option
:selected会选择被选中的option元素
");
window.frames["iframe_show978"].document.write(decodeHtml($("textarea#stepcodeTextarea978").val()));
window.frames["iframe_show978"].document.close();
$(window.frames["iframe_show978"]).load(function(){
$("#iframe_show978").height($("#iframe_show978").contents().find("body").height()+showittryitheight);
});
$("#iframe_show978").height($("#iframe_show978").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$(".b").click(function(){
var value = $(this).val();
$("td[rowspan!=13] "+value).toggle(500);
});
$(".b2").click(function(){
var value = $(this).val();
var options = $("td[rowspan!=13] "+value);
alert("选中了"+options.length+"条记录!");
});
});
</script>
<style>
table{
border-collapse:collapse;
table-layout:fixed;
width:80%;
}
table td{
border-bottom: 1px solid #ddd;
padding-bottom: 5px;
padding-top: 5px;
}
div button{
display:block;
}
.border{
border: 1px blue solid;
}
</style>
<table>
<tr>
<td rowspan="13" valign="top" width="120">
<div >
<button value=":enabled" class="b">切换:enabled</button>
<button value=":disabled" class="b">切换:disabled</button>
<button value=":checked" class="b">切换:checked</button>
<button value=":selected" class="b2">:selected数量</button>
</div>
</td>
<td width="120">说明</td>
<td width="120">表单对象属性</td>
<td width="100px">示例</td>
</tr>
<tr>
<td >enabled的按钮</td>
<td >:enabled</td>
<td><input type="button" enabled="enabled" value="enabled的按钮"/></td>
</tr>
<tr>
<td >disabled的按钮</td>
<td >:disabled</td>
<td><input type="button" disabled="disabled" value="disabled的按钮"/></td>
</tr>
<td >选中的复选框</td>
<td >:checked</td>
<td>
<input type="radio" checked="checked" ><br>
<input type="radio" ><br>
<input type="checkbox" ><br>
<input type="checkbox" checked="checked" >
</td>
<tr>
<td>选中的下拉列表</td>
<td >:selected</td>
<td>
<select size="3" multiple="multiple">
<option selected="selected">苍老师</option>
<option >高树玛利亚</option>
<option selected="selected">遥美</option>
</select>
</td>
</table>
<form>
</form>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$(".b").click(function(){
var value = $(this).val();
$("td[rowspan!=13] "+value).toggle(500);
});
$(".b2").click(function(){
var value = $(this).val();
var options = $("td[rowspan!=13] "+value);
alert("选中了"+options.length+"条记录!");
});
});
</script>
<style>
table{
border-collapse:collapse;
table-layout:fixed;
width:80%;
}
table td{
border-bottom: 1px solid #ddd;
padding-bottom: 5px;
padding-top: 5px;
}
div button{
display:block;
}
.border{
border: 1px blue solid;
}
</style>
<table>
<tr>
<td rowspan="13" valign="top" width="120">
<div >
<button value=":enabled" class="b">切换:enabled</button>
<button value=":disabled" class="b">切换:disabled</button>
<button value=":checked" class="b">切换:checked</button>
<button value=":selected" class="b2">:selected数量</button>
</div>
</td>
<td width="120">说明</td>
<td width="120">表单对象属性</td>
<td width="100px">示例</td>
</tr>
<tr>
<td >enabled的按钮</td>
<td >:enabled</td>
<td><input type="button" enabled="enabled" value="enabled的按钮"/></td>
</tr>
<tr>
<td >disabled的按钮</td>
<td >:disabled</td>
<td><input type="button" disabled="disabled" value="disabled的按钮"/></td>
</tr>
<td >选中的复选框</td>
<td >:checked</td>
<td>
<input type="radio" checked="checked" ><br>
<input type="radio" ><br>
<input type="checkbox" ><br>
<input type="checkbox" checked="checked" >
</td>
<tr>
<td>选中的下拉列表</td>
<td >:selected</td>
<td>
<select size="3" multiple="multiple">
<option selected="selected">苍老师</option>
<option >高树玛利亚</option>
<option selected="selected">遥美</option>
</select>
</td>
</table>
<form>
</form>
");
window.frames["iframe978"].document.write(decodeHtml(code978));
window.frames["iframe978"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe978"]).load(function(){
$("#iframe978").height($("#iframe978").contents().find("body").height()+showittryitheight);
});
$("#iframe978").height($("#iframe978").contents().find("body").height()+showittryitheight);
alreadyWriteCode978 = code978;
$("#rendering978").hide();
$("#rendered978").show();
}
var tRereshRetry2DemoPanel978 = setInterval(rereshRetry2DemoPanel978,1000);
var binded978 = false;
$("textarea#stepcodeTextarea978").keyup(function(){
if(!binded978){
$(window).bind('beforeunload',function(){
binded978 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code978 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code978!=newCode){
// window.frames["iframe978"].document.write("
");
// window.frames["iframe978"].document.write(decodeHtml($("textarea#stepcodeTextarea978").val()));
// window.frames["iframe978"].document.close();
// $(window.frames["iframe978"]).load(function(){
// $("#iframe978").height($("#iframe978").contents().find("body").height()+showittryitheight);
// });
// code978 = newCode;
// }
});
$(".tryButton978").click(function(){
$("#tryDiv978").show();
$("#stepcodeTextarea978").focus();
$("#stepcodeTextarea978").height(200);
$("#iframe978").height(0);
window.frames["iframe978"].document.write("
");
window.frames["iframe978"].document.write(decodeHtml($("textarea#stepcodeTextarea978").val()));
window.frames["iframe978"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe978"]).load(function(){
$("#iframe978").height($("#iframe978").contents().find("body").height()+showittryitheight);
});
$("#iframe978").height($("#iframe978").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor978.focus();
editor978.setSize(null, "250");
$("#rendering978").hide();
$("#rendered978").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 editor978 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea978"), {
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);
}
}
});
editor978.on("change",function(doc){
if(!binded978){
$(window).bind('beforeunload',function(){
binded978 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code978 = newCode;
$("textarea#stepcodeTextarea978").val(newCode);
if(alreadyWriteCode978!=code978){
lastModifedTime978 = new Date().getTime();
$("#rendering978").show();
$("#rendered978").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor978 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor978.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv978").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
在监听函数中使用 $(this),即表示触发该事件的组件。
");
window.frames["iframe_show1225"].document.write(decodeHtml($("textarea#stepcodeTextarea1225").val()));
window.frames["iframe_show1225"].document.close();
$(window.frames["iframe_show1225"]).load(function(){
$("#iframe_show1225").height($("#iframe_show1225").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1225").height($("#iframe_show1225").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$(this).hide();
});
});
</script>
<button id="b1">点击隐藏</button>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$(this).hide();
});
});
</script>
<button id="b1">点击隐藏</button>
");
window.frames["iframe1225"].document.write(decodeHtml(code1225));
window.frames["iframe1225"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1225"]).load(function(){
$("#iframe1225").height($("#iframe1225").contents().find("body").height()+showittryitheight);
});
$("#iframe1225").height($("#iframe1225").contents().find("body").height()+showittryitheight);
alreadyWriteCode1225 = code1225;
$("#rendering1225").hide();
$("#rendered1225").show();
}
var tRereshRetry2DemoPanel1225 = setInterval(rereshRetry2DemoPanel1225,1000);
var binded1225 = false;
$("textarea#stepcodeTextarea1225").keyup(function(){
if(!binded1225){
$(window).bind('beforeunload',function(){
binded1225 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1225 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1225!=newCode){
// window.frames["iframe1225"].document.write("
");
// window.frames["iframe1225"].document.write(decodeHtml($("textarea#stepcodeTextarea1225").val()));
// window.frames["iframe1225"].document.close();
// $(window.frames["iframe1225"]).load(function(){
// $("#iframe1225").height($("#iframe1225").contents().find("body").height()+showittryitheight);
// });
// code1225 = newCode;
// }
});
$(".tryButton1225").click(function(){
$("#tryDiv1225").show();
$("#stepcodeTextarea1225").focus();
$("#stepcodeTextarea1225").height(200);
$("#iframe1225").height(0);
window.frames["iframe1225"].document.write("
");
window.frames["iframe1225"].document.write(decodeHtml($("textarea#stepcodeTextarea1225").val()));
window.frames["iframe1225"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1225"]).load(function(){
$("#iframe1225").height($("#iframe1225").contents().find("body").height()+showittryitheight);
});
$("#iframe1225").height($("#iframe1225").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1225.focus();
editor1225.setSize(null, "250");
$("#rendering1225").hide();
$("#rendered1225").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 editor1225 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1225"), {
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);
}
}
});
editor1225.on("change",function(doc){
if(!binded1225){
$(window).bind('beforeunload',function(){
binded1225 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1225 = newCode;
$("textarea#stepcodeTextarea1225").val(newCode);
if(alreadyWriteCode1225!=code1225){
lastModifedTime1225 = new Date().getTime();
$("#rendering1225").show();
$("#rendered1225").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1225 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1225.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1225").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|