|
关键字 |
简介 |
示例代码 |
attr
|
获取
|
示例代码
|
attr(属性,值)
|
修改
|
示例代码
|
removeAttr
|
删除
|
示例代码
|
prop与attr
|
prop与attr的区别
|
示例代码
|
示例
1
:
获取
示例
2
:
修改
示例
3
:
删除
示例
4
:
prop与attr的区别
");
window.frames["iframe_show980"].document.write(decodeHtml($("textarea#stepcodeTextarea980").val()));
window.frames["iframe_show980"].document.close();
$(window.frames["iframe_show980"]).load(function(){
$("#iframe_show980").height($("#iframe_show980").contents().find("body").height()+showittryitheight);
});
$("#iframe_show980").height($("#iframe_show980").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("align属性是:" + $("#h").attr("align") );
});
$("#b2").click(function(){
alert("game属性是:" + $("#h").attr("game") );
});
});
</script>
<button id="b1">获取align属性</button>
<button id="b2">获取自定义属性 game</button>
<br>
<br>
<h1 id="h" align="center" game="LOL">居中标题</h1>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
alert("align属性是:" + $("#h").attr("align") );
});
$("#b2").click(function(){
alert("game属性是:" + $("#h").attr("game") );
});
});
</script>
<button id="b1">获取align属性</button>
<button id="b2">获取自定义属性 game</button>
<br>
<br>
<h1 id="h" align="center" game="LOL">居中标题</h1>
");
window.frames["iframe980"].document.write(decodeHtml(code980));
window.frames["iframe980"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe980"]).load(function(){
$("#iframe980").height($("#iframe980").contents().find("body").height()+showittryitheight);
});
$("#iframe980").height($("#iframe980").contents().find("body").height()+showittryitheight);
alreadyWriteCode980 = code980;
$("#rendering980").hide();
$("#rendered980").show();
}
var tRereshRetry2DemoPanel980 = setInterval(rereshRetry2DemoPanel980,1000);
var binded980 = false;
$("textarea#stepcodeTextarea980").keyup(function(){
if(!binded980){
$(window).bind('beforeunload',function(){
binded980 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code980 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code980!=newCode){
// window.frames["iframe980"].document.write("
");
// window.frames["iframe980"].document.write(decodeHtml($("textarea#stepcodeTextarea980").val()));
// window.frames["iframe980"].document.close();
// $(window.frames["iframe980"]).load(function(){
// $("#iframe980").height($("#iframe980").contents().find("body").height()+showittryitheight);
// });
// code980 = newCode;
// }
});
$(".tryButton980").click(function(){
$("#tryDiv980").show();
$("#stepcodeTextarea980").focus();
$("#stepcodeTextarea980").height(200);
$("#iframe980").height(0);
window.frames["iframe980"].document.write("
");
window.frames["iframe980"].document.write(decodeHtml($("textarea#stepcodeTextarea980").val()));
window.frames["iframe980"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe980"]).load(function(){
$("#iframe980").height($("#iframe980").contents().find("body").height()+showittryitheight);
});
$("#iframe980").height($("#iframe980").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor980.focus();
editor980.setSize(null, "250");
$("#rendering980").hide();
$("#rendered980").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 editor980 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea980"), {
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);
}
}
});
editor980.on("change",function(doc){
if(!binded980){
$(window).bind('beforeunload',function(){
binded980 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code980 = newCode;
$("textarea#stepcodeTextarea980").val(newCode);
if(alreadyWriteCode980!=code980){
lastModifedTime980 = new Date().getTime();
$("#rendering980").show();
$("#rendered980").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor980 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor980.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv980").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show981"].document.write(decodeHtml($("textarea#stepcodeTextarea981").val()));
window.frames["iframe_show981"].document.close();
$(window.frames["iframe_show981"]).load(function(){
$("#iframe_show981").height($("#iframe_show981").contents().find("body").height()+showittryitheight);
});
$("#iframe_show981").height($("#iframe_show981").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(){
$("#h").attr("align","right") ;
});
});
</script>
<button id="b1">修改align属性为right</button>
<br>
<br>
<h1 id="h" align="center" >居中标题</h1>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("#h").attr("align","right") ;
});
});
</script>
<button id="b1">修改align属性为right</button>
<br>
<br>
<h1 id="h" align="center" >居中标题</h1>
");
window.frames["iframe981"].document.write(decodeHtml(code981));
window.frames["iframe981"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe981"]).load(function(){
$("#iframe981").height($("#iframe981").contents().find("body").height()+showittryitheight);
});
$("#iframe981").height($("#iframe981").contents().find("body").height()+showittryitheight);
alreadyWriteCode981 = code981;
$("#rendering981").hide();
$("#rendered981").show();
}
var tRereshRetry2DemoPanel981 = setInterval(rereshRetry2DemoPanel981,1000);
var binded981 = false;
$("textarea#stepcodeTextarea981").keyup(function(){
if(!binded981){
$(window).bind('beforeunload',function(){
binded981 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code981 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code981!=newCode){
// window.frames["iframe981"].document.write("
");
// window.frames["iframe981"].document.write(decodeHtml($("textarea#stepcodeTextarea981").val()));
// window.frames["iframe981"].document.close();
// $(window.frames["iframe981"]).load(function(){
// $("#iframe981").height($("#iframe981").contents().find("body").height()+showittryitheight);
// });
// code981 = newCode;
// }
});
$(".tryButton981").click(function(){
$("#tryDiv981").show();
$("#stepcodeTextarea981").focus();
$("#stepcodeTextarea981").height(200);
$("#iframe981").height(0);
window.frames["iframe981"].document.write("
");
window.frames["iframe981"].document.write(decodeHtml($("textarea#stepcodeTextarea981").val()));
window.frames["iframe981"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe981"]).load(function(){
$("#iframe981").height($("#iframe981").contents().find("body").height()+showittryitheight);
});
$("#iframe981").height($("#iframe981").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor981.focus();
editor981.setSize(null, "250");
$("#rendering981").hide();
$("#rendered981").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 editor981 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea981"), {
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);
}
}
});
editor981.on("change",function(doc){
if(!binded981){
$(window).bind('beforeunload',function(){
binded981 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code981 = newCode;
$("textarea#stepcodeTextarea981").val(newCode);
if(alreadyWriteCode981!=code981){
lastModifedTime981 = new Date().getTime();
$("#rendering981").show();
$("#rendered981").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor981 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor981.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv981").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show982"].document.write(decodeHtml($("textarea#stepcodeTextarea982").val()));
window.frames["iframe_show982"].document.close();
$(window.frames["iframe_show982"]).load(function(){
$("#iframe_show982").height($("#iframe_show982").contents().find("body").height()+showittryitheight);
});
$("#iframe_show982").height($("#iframe_show982").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(){
$("#h").removeAttr("align");
});
});
</script>
<button id="b1">删除align属性</button>
<br>
<br>
<h1 id="h" align="center" game="LOL">居中标题</h1>
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
$("#h").removeAttr("align");
});
});
</script>
<button id="b1">删除align属性</button>
<br>
<br>
<h1 id="h" align="center" game="LOL">居中标题</h1>
");
window.frames["iframe982"].document.write(decodeHtml(code982));
window.frames["iframe982"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe982"]).load(function(){
$("#iframe982").height($("#iframe982").contents().find("body").height()+showittryitheight);
});
$("#iframe982").height($("#iframe982").contents().find("body").height()+showittryitheight);
alreadyWriteCode982 = code982;
$("#rendering982").hide();
$("#rendered982").show();
}
var tRereshRetry2DemoPanel982 = setInterval(rereshRetry2DemoPanel982,1000);
var binded982 = false;
$("textarea#stepcodeTextarea982").keyup(function(){
if(!binded982){
$(window).bind('beforeunload',function(){
binded982 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code982 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code982!=newCode){
// window.frames["iframe982"].document.write("
");
// window.frames["iframe982"].document.write(decodeHtml($("textarea#stepcodeTextarea982").val()));
// window.frames["iframe982"].document.close();
// $(window.frames["iframe982"]).load(function(){
// $("#iframe982").height($("#iframe982").contents().find("body").height()+showittryitheight);
// });
// code982 = newCode;
// }
});
$(".tryButton982").click(function(){
$("#tryDiv982").show();
$("#stepcodeTextarea982").focus();
$("#stepcodeTextarea982").height(200);
$("#iframe982").height(0);
window.frames["iframe982"].document.write("
");
window.frames["iframe982"].document.write(decodeHtml($("textarea#stepcodeTextarea982").val()));
window.frames["iframe982"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe982"]).load(function(){
$("#iframe982").height($("#iframe982").contents().find("body").height()+showittryitheight);
});
$("#iframe982").height($("#iframe982").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor982.focus();
editor982.setSize(null, "250");
$("#rendering982").hide();
$("#rendered982").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 editor982 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea982"), {
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);
}
}
});
editor982.on("change",function(doc){
if(!binded982){
$(window).bind('beforeunload',function(){
binded982 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code982 = newCode;
$("textarea#stepcodeTextarea982").val(newCode);
if(alreadyWriteCode982!=code982){
lastModifedTime982 = new Date().getTime();
$("#rendering982").show();
$("#rendered982").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor982 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor982.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv982").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
与prop一样attr也可以用来获取与设置元素的属性。 区别在于,对于自定义属性和选中属性的处理。 选中属性指的是 checked,selected 这2种属性 1. 对于自定义属性 attr能够获取,prop不能获取 2. 对于选中属性 attr 只能获取初始值, 无论是否变化 prop 能够访问变化后的值,并且以true|false的布尔型返回。 所以在访问表单对象属性的时候,应该采用prop而非attr
");
window.frames["iframe_show1223"].document.write(decodeHtml($("textarea#stepcodeTextarea1223").val()));
window.frames["iframe_show1223"].document.close();
$(window.frames["iframe_show1223"]).load(function(){
$("#iframe_show1223").height($("#iframe_show1223").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1223").height($("#iframe_show1223").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("game属性是:" + $("#c").attr("game") );
});
$("#b2").click(function(){
alert("game属性是:" + $("#c").prop("game") );
});
$("#b3").click(function(){
alert("checked属性是:" + $("#c").attr("checked") );
});
$("#b4").click(function(){
alert("checked属性是:" + $("#c").prop("checked") );
});
});
</script>
<style>
button{
display:block;
}
</style>
<button id="b1">通过attr获取自定义属性 game</button>
<button id="b2">通过prop获取自定义属性 game</button>
<button id="b3">通过attr获取 checked属性</button>
<button id="b4">通过prop获取 checked属性</button>
<br>
<br>
<input type="checkbox" id="c" game="LOL" checked="checked"> 选中的复选框
<script src="http://127.0.0.1/study/jquery.min.js"></script>
<script>
$(function(){
$("#b1").click(function(){
alert("game属性是:" + $("#c").attr("game") );
});
$("#b2").click(function(){
alert("game属性是:" + $("#c").prop("game") );
});
$("#b3").click(function(){
alert("checked属性是:" + $("#c").attr("checked") );
});
$("#b4").click(function(){
alert("checked属性是:" + $("#c").prop("checked") );
});
});
</script>
<style>
button{
display:block;
}
</style>
<button id="b1">通过attr获取自定义属性 game</button>
<button id="b2">通过prop获取自定义属性 game</button>
<button id="b3">通过attr获取 checked属性</button>
<button id="b4">通过prop获取 checked属性</button>
<br>
<br>
<input type="checkbox" id="c" game="LOL" checked="checked"> 选中的复选框
");
window.frames["iframe1223"].document.write(decodeHtml(code1223));
window.frames["iframe1223"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1223"]).load(function(){
$("#iframe1223").height($("#iframe1223").contents().find("body").height()+showittryitheight);
});
$("#iframe1223").height($("#iframe1223").contents().find("body").height()+showittryitheight);
alreadyWriteCode1223 = code1223;
$("#rendering1223").hide();
$("#rendered1223").show();
}
var tRereshRetry2DemoPanel1223 = setInterval(rereshRetry2DemoPanel1223,1000);
var binded1223 = false;
$("textarea#stepcodeTextarea1223").keyup(function(){
if(!binded1223){
$(window).bind('beforeunload',function(){
binded1223 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1223 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1223!=newCode){
// window.frames["iframe1223"].document.write("
");
// window.frames["iframe1223"].document.write(decodeHtml($("textarea#stepcodeTextarea1223").val()));
// window.frames["iframe1223"].document.close();
// $(window.frames["iframe1223"]).load(function(){
// $("#iframe1223").height($("#iframe1223").contents().find("body").height()+showittryitheight);
// });
// code1223 = newCode;
// }
});
$(".tryButton1223").click(function(){
$("#tryDiv1223").show();
$("#stepcodeTextarea1223").focus();
$("#stepcodeTextarea1223").height(200);
$("#iframe1223").height(0);
window.frames["iframe1223"].document.write("
");
window.frames["iframe1223"].document.write(decodeHtml($("textarea#stepcodeTextarea1223").val()));
window.frames["iframe1223"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1223"]).load(function(){
$("#iframe1223").height($("#iframe1223").contents().find("body").height()+showittryitheight);
});
$("#iframe1223").height($("#iframe1223").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1223.focus();
editor1223.setSize(null, "250");
$("#rendering1223").hide();
$("#rendered1223").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 editor1223 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1223"), {
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);
}
}
});
editor1223.on("change",function(doc){
if(!binded1223){
$(window).bind('beforeunload',function(){
binded1223 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1223 = newCode;
$("textarea#stepcodeTextarea1223").val(newCode);
if(alreadyWriteCode1223!=code1223){
lastModifedTime1223 = new Date().getTime();
$("#rendering1223").show();
$("#rendered1223").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1223 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1223.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1223").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|