|
关键字 |
简介 |
示例代码 |
val
|
取值
|
示例代码
|
html
|
获取元素内容,如果有子元素,保留标签
|
示例代码
|
text
|
获取元素内容,如果有子元素,不包含子元素标签
|
示例代码
|
示例
1
:
取值
示例
2
:
获取元素内容,如果有子元素,保留标签
示例
3
:
获取元素内容,如果有子元素,不包含子元素标签
通过JQuery对象的val()方法获取值
相当于 document.getElementById("input1").value;
");
window.frames["iframe_show1220"].document.write(decodeHtml($("textarea#stepcodeTextarea1220").val()));
window.frames["iframe_show1220"].document.close();
$(window.frames["iframe_show1220"]).load(function(){
$("#iframe_show1220").height($("#iframe_show1220").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1220").height($("#iframe_show1220").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(){
alert($("#input1").val());
});
});
</script>
<button id="b1">取值</button>
<br>
<br>
<input type="text" id="input1" value="默认值">
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
alert($("#input1").val());
});
});
</script>
<button id="b1">取值</button>
<br>
<br>
<input type="text" id="input1" value="默认值">
");
window.frames["iframe1220"].document.write(decodeHtml(code1220));
window.frames["iframe1220"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1220"]).load(function(){
$("#iframe1220").height($("#iframe1220").contents().find("body").height()+showittryitheight);
});
$("#iframe1220").height($("#iframe1220").contents().find("body").height()+showittryitheight);
alreadyWriteCode1220 = code1220;
$("#rendering1220").hide();
$("#rendered1220").show();
}
var tRereshRetry2DemoPanel1220 = setInterval(rereshRetry2DemoPanel1220,1000);
var binded1220 = false;
$("textarea#stepcodeTextarea1220").keyup(function(){
if(!binded1220){
$(window).bind('beforeunload',function(){
binded1220 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1220 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1220!=newCode){
// window.frames["iframe1220"].document.write("
");
// window.frames["iframe1220"].document.write(decodeHtml($("textarea#stepcodeTextarea1220").val()));
// window.frames["iframe1220"].document.close();
// $(window.frames["iframe1220"]).load(function(){
// $("#iframe1220").height($("#iframe1220").contents().find("body").height()+showittryitheight);
// });
// code1220 = newCode;
// }
});
$(".tryButton1220").click(function(){
$("#tryDiv1220").show();
$("#stepcodeTextarea1220").focus();
$("#stepcodeTextarea1220").height(200);
$("#iframe1220").height(0);
window.frames["iframe1220"].document.write("
");
window.frames["iframe1220"].document.write(decodeHtml($("textarea#stepcodeTextarea1220").val()));
window.frames["iframe1220"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1220"]).load(function(){
$("#iframe1220").height($("#iframe1220").contents().find("body").height()+showittryitheight);
});
$("#iframe1220").height($("#iframe1220").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1220.focus();
editor1220.setSize(null, "250");
$("#rendering1220").hide();
$("#rendered1220").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 editor1220 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1220"), {
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);
}
}
});
editor1220.on("change",function(doc){
if(!binded1220){
$(window).bind('beforeunload',function(){
binded1220 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1220 = newCode;
$("textarea#stepcodeTextarea1220").val(newCode);
if(alreadyWriteCode1220!=code1220){
lastModifedTime1220 = new Date().getTime();
$("#rendering1220").show();
$("#rendered1220").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1220 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1220.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1220").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
2
:
获取元素内容,如果有子元素,保留标签
顶
折
通过html() 获取元素内容,如果有子元素,保留标签
");
window.frames["iframe_show1221"].document.write(decodeHtml($("textarea#stepcodeTextarea1221").val()));
window.frames["iframe_show1221"].document.close();
$(window.frames["iframe_show1221"]).load(function(){
$("#iframe_show1221").height($("#iframe_show1221").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1221").height($("#iframe_show1221").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(){
alert($("#d1").html());
});
});
</script>
<button id="b1">获取文本内容</button>
<br>
<br>
<div id="d1">
这是div的内容
<span>这是div里的span
</span>
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
alert($("#d1").html());
});
});
</script>
<button id="b1">获取文本内容</button>
<br>
<br>
<div id="d1">
这是div的内容
<span>这是div里的span
</span>
</div>
");
window.frames["iframe1221"].document.write(decodeHtml(code1221));
window.frames["iframe1221"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1221"]).load(function(){
$("#iframe1221").height($("#iframe1221").contents().find("body").height()+showittryitheight);
});
$("#iframe1221").height($("#iframe1221").contents().find("body").height()+showittryitheight);
alreadyWriteCode1221 = code1221;
$("#rendering1221").hide();
$("#rendered1221").show();
}
var tRereshRetry2DemoPanel1221 = setInterval(rereshRetry2DemoPanel1221,1000);
var binded1221 = false;
$("textarea#stepcodeTextarea1221").keyup(function(){
if(!binded1221){
$(window).bind('beforeunload',function(){
binded1221 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1221 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1221!=newCode){
// window.frames["iframe1221"].document.write("
");
// window.frames["iframe1221"].document.write(decodeHtml($("textarea#stepcodeTextarea1221").val()));
// window.frames["iframe1221"].document.close();
// $(window.frames["iframe1221"]).load(function(){
// $("#iframe1221").height($("#iframe1221").contents().find("body").height()+showittryitheight);
// });
// code1221 = newCode;
// }
});
$(".tryButton1221").click(function(){
$("#tryDiv1221").show();
$("#stepcodeTextarea1221").focus();
$("#stepcodeTextarea1221").height(200);
$("#iframe1221").height(0);
window.frames["iframe1221"].document.write("
");
window.frames["iframe1221"].document.write(decodeHtml($("textarea#stepcodeTextarea1221").val()));
window.frames["iframe1221"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1221"]).load(function(){
$("#iframe1221").height($("#iframe1221").contents().find("body").height()+showittryitheight);
});
$("#iframe1221").height($("#iframe1221").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1221.focus();
editor1221.setSize(null, "250");
$("#rendering1221").hide();
$("#rendered1221").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 editor1221 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1221"), {
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);
}
}
});
editor1221.on("change",function(doc){
if(!binded1221){
$(window).bind('beforeunload',function(){
binded1221 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1221 = newCode;
$("textarea#stepcodeTextarea1221").val(newCode);
if(alreadyWriteCode1221!=code1221){
lastModifedTime1221 = new Date().getTime();
$("#rendering1221").show();
$("#rendered1221").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1221 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1221.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1221").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
3
:
获取元素内容,如果有子元素,不包含子元素标签
顶
折
通过text() 获取元素内容,如果有子元素,不包含标签
");
window.frames["iframe_show1222"].document.write(decodeHtml($("textarea#stepcodeTextarea1222").val()));
window.frames["iframe_show1222"].document.close();
$(window.frames["iframe_show1222"]).load(function(){
$("#iframe_show1222").height($("#iframe_show1222").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1222").height($("#iframe_show1222").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(){
alert($("#d1").text());
});
});
</script>
<button id="b1">获取文本内容</button>
<br>
<br>
<div id="d1">
这是div的内容
<span>这是div里的span
</span>
</div>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
alert($("#d1").text());
});
});
</script>
<button id="b1">获取文本内容</button>
<br>
<br>
<div id="d1">
这是div的内容
<span>这是div里的span
</span>
</div>
");
window.frames["iframe1222"].document.write(decodeHtml(code1222));
window.frames["iframe1222"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1222"]).load(function(){
$("#iframe1222").height($("#iframe1222").contents().find("body").height()+showittryitheight);
});
$("#iframe1222").height($("#iframe1222").contents().find("body").height()+showittryitheight);
alreadyWriteCode1222 = code1222;
$("#rendering1222").hide();
$("#rendered1222").show();
}
var tRereshRetry2DemoPanel1222 = setInterval(rereshRetry2DemoPanel1222,1000);
var binded1222 = false;
$("textarea#stepcodeTextarea1222").keyup(function(){
if(!binded1222){
$(window).bind('beforeunload',function(){
binded1222 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1222 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1222!=newCode){
// window.frames["iframe1222"].document.write("
");
// window.frames["iframe1222"].document.write(decodeHtml($("textarea#stepcodeTextarea1222").val()));
// window.frames["iframe1222"].document.close();
// $(window.frames["iframe1222"]).load(function(){
// $("#iframe1222").height($("#iframe1222").contents().find("body").height()+showittryitheight);
// });
// code1222 = newCode;
// }
});
$(".tryButton1222").click(function(){
$("#tryDiv1222").show();
$("#stepcodeTextarea1222").focus();
$("#stepcodeTextarea1222").height(200);
$("#iframe1222").height(0);
window.frames["iframe1222"].document.write("
");
window.frames["iframe1222"].document.write(decodeHtml($("textarea#stepcodeTextarea1222").val()));
window.frames["iframe1222"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1222"]).load(function(){
$("#iframe1222").height($("#iframe1222").contents().find("body").height()+showittryitheight);
});
$("#iframe1222").height($("#iframe1222").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1222.focus();
editor1222.setSize(null, "250");
$("#rendering1222").hide();
$("#rendered1222").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 editor1222 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1222"), {
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);
}
}
});
editor1222.on("change",function(doc){
if(!binded1222){
$(window).bind('beforeunload',function(){
binded1222 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1222 = newCode;
$("textarea#stepcodeTextarea1222").val(newCode);
if(alreadyWriteCode1222!=code1222){
lastModifedTime1222 = new Date().getTime();
$("#rendering1222").show();
$("#rendered1222").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1222 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1222.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1222").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|