|
工具版本兼容问题
通过AJAX Asynchronous JAvaScript and XML 实现异步刷新
示例
1
:
用于用户名校验的页面
示例
2
:
不使用AJAX 通过刷新页面验证账号是否存在
示例
3
:
使用AJAX 通过无刷新验证账号是否存在
");
window.frames["iframe_show1230"].document.write(decodeHtml($("textarea#stepcodeTextarea1230").val()));
window.frames["iframe_show1230"].document.close();
$(window.frames["iframe_show1230"]).load(function(){
$("#iframe_show1230").height($("#iframe_show1230").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1230").height($("#iframe_show1230").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<html>
<a href="http://127.0.0.1/study/checkName.jsp?name=abc">checkName.jsp?name=abc</a>
<br>
<a href="http://127.0.0.1/study/checkName.jsp?name=def">checkName.jsp?name=def</a>
</html>
<html>
<a href="http://127.0.0.1/study/checkName.jsp?name=abc">checkName.jsp?name=abc</a>
<br>
<a href="http://127.0.0.1/study/checkName.jsp?name=def">checkName.jsp?name=def</a>
</html>
");
window.frames["iframe1230"].document.write(decodeHtml(code1230));
window.frames["iframe1230"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1230"]).load(function(){
$("#iframe1230").height($("#iframe1230").contents().find("body").height()+showittryitheight);
});
$("#iframe1230").height($("#iframe1230").contents().find("body").height()+showittryitheight);
alreadyWriteCode1230 = code1230;
$("#rendering1230").hide();
$("#rendered1230").show();
}
var tRereshRetry2DemoPanel1230 = setInterval(rereshRetry2DemoPanel1230,1000);
var binded1230 = false;
$("textarea#stepcodeTextarea1230").keyup(function(){
if(!binded1230){
$(window).bind('beforeunload',function(){
binded1230 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1230 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1230!=newCode){
// window.frames["iframe1230"].document.write("
");
// window.frames["iframe1230"].document.write(decodeHtml($("textarea#stepcodeTextarea1230").val()));
// window.frames["iframe1230"].document.close();
// $(window.frames["iframe1230"]).load(function(){
// $("#iframe1230").height($("#iframe1230").contents().find("body").height()+showittryitheight);
// });
// code1230 = newCode;
// }
});
$(".tryButton1230").click(function(){
$("#tryDiv1230").show();
$("#stepcodeTextarea1230").focus();
$("#stepcodeTextarea1230").height(200);
$("#iframe1230").height(0);
window.frames["iframe1230"].document.write("
");
window.frames["iframe1230"].document.write(decodeHtml($("textarea#stepcodeTextarea1230").val()));
window.frames["iframe1230"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1230"]).load(function(){
$("#iframe1230").height($("#iframe1230").contents().find("body").height()+showittryitheight);
});
$("#iframe1230").height($("#iframe1230").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1230.focus();
editor1230.setSize(null, "250");
$("#rendering1230").hide();
$("#rendered1230").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 editor1230 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1230"), {
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);
}
}
});
editor1230.on("change",function(doc){
if(!binded1230){
$(window).bind('beforeunload',function(){
binded1230 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1230 = newCode;
$("textarea#stepcodeTextarea1230").val(newCode);
if(alreadyWriteCode1230!=code1230){
lastModifedTime1230 = new Date().getTime();
$("#rendering1230").show();
$("#rendered1230").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1230 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1230.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1230").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
2
:
不使用AJAX 通过刷新页面验证账号是否存在
顶
折
如果不使用AJAX,传统的方法需要通过提交数据 刷新页面来获知用户名是否存在。 提示:使用F5回到原来页面
");
window.frames["iframe_show1228"].document.write(decodeHtml($("textarea#stepcodeTextarea1228").val()));
window.frames["iframe_show1228"].document.close();
$(window.frames["iframe_show1228"]).load(function(){
$("#iframe_show1228").height($("#iframe_show1228").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1228").height($("#iframe_show1228").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<form action="http://127.0.0.1/study/checkName.jsp">
输入账号 <input name="name" type="text" value="abc">
<input type="submit" value="验证账号是否存在">
</form>
<form action="http://127.0.0.1/study/checkName.jsp">
输入账号 <input name="name" type="text" value="abc">
<input type="submit" value="验证账号是否存在">
</form>
");
window.frames["iframe1228"].document.write(decodeHtml(code1228));
window.frames["iframe1228"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1228"]).load(function(){
$("#iframe1228").height($("#iframe1228").contents().find("body").height()+showittryitheight);
});
$("#iframe1228").height($("#iframe1228").contents().find("body").height()+showittryitheight);
alreadyWriteCode1228 = code1228;
$("#rendering1228").hide();
$("#rendered1228").show();
}
var tRereshRetry2DemoPanel1228 = setInterval(rereshRetry2DemoPanel1228,1000);
var binded1228 = false;
$("textarea#stepcodeTextarea1228").keyup(function(){
if(!binded1228){
$(window).bind('beforeunload',function(){
binded1228 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1228 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1228!=newCode){
// window.frames["iframe1228"].document.write("
");
// window.frames["iframe1228"].document.write(decodeHtml($("textarea#stepcodeTextarea1228").val()));
// window.frames["iframe1228"].document.close();
// $(window.frames["iframe1228"]).load(function(){
// $("#iframe1228").height($("#iframe1228").contents().find("body").height()+showittryitheight);
// });
// code1228 = newCode;
// }
});
$(".tryButton1228").click(function(){
$("#tryDiv1228").show();
$("#stepcodeTextarea1228").focus();
$("#stepcodeTextarea1228").height(200);
$("#iframe1228").height(0);
window.frames["iframe1228"].document.write("
");
window.frames["iframe1228"].document.write(decodeHtml($("textarea#stepcodeTextarea1228").val()));
window.frames["iframe1228"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1228"]).load(function(){
$("#iframe1228").height($("#iframe1228").contents().find("body").height()+showittryitheight);
});
$("#iframe1228").height($("#iframe1228").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1228.focus();
editor1228.setSize(null, "250");
$("#rendering1228").hide();
$("#rendered1228").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 editor1228 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1228"), {
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);
}
}
});
editor1228.on("change",function(doc){
if(!binded1228){
$(window).bind('beforeunload',function(){
binded1228 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1228 = newCode;
$("textarea#stepcodeTextarea1228").val(newCode);
if(alreadyWriteCode1228!=code1228){
lastModifedTime1228 = new Date().getTime();
$("#rendering1228").show();
$("#rendered1228").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1228 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1228.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1228").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
3
:
使用AJAX 通过无刷新验证账号是否存在
顶
折
");
window.frames["iframe_show1229"].document.write(decodeHtml($("textarea#stepcodeTextarea1229").val()));
window.frames["iframe_show1229"].document.close();
$(window.frames["iframe_show1229"]).load(function(){
$("#iframe_show1229").height($("#iframe_show1229").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1229").height($("#iframe_show1229").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<span>输入账号 :</span>
<input id="name" name="name" onkeyup="check()" type="text">
<span id="checkResult"></span>
<script>
var xmlhttp;
function check(){
var name = document.getElementById("name").value;
var url = "http://127.0.0.1/study/checkName.jsp?name="+name;
xmlhttp =new XMLHttpRequest();
xmlhttp.onreadystatechange=checkResult; //响应函数
xmlhttp.open("GET",url,true); //设置访问的页面
xmlhttp.send(null); //执行访问
}
function checkResult(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById('checkResult').innerHTML=xmlhttp.responseText;
}
</script>
<span>输入账号 :</span>
<input id="name" name="name" onkeyup="check()" type="text">
<span id="checkResult"></span>
<script>
var xmlhttp;
function check(){
var name = document.getElementById("name").value;
var url = "http://127.0.0.1/study/checkName.jsp?name="+name;
xmlhttp =new XMLHttpRequest();
xmlhttp.onreadystatechange=checkResult; //响应函数
xmlhttp.open("GET",url,true); //设置访问的页面
xmlhttp.send(null); //执行访问
}
function checkResult(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById('checkResult').innerHTML=xmlhttp.responseText;
}
</script>
");
window.frames["iframe1229"].document.write(decodeHtml(code1229));
window.frames["iframe1229"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1229"]).load(function(){
$("#iframe1229").height($("#iframe1229").contents().find("body").height()+showittryitheight);
});
$("#iframe1229").height($("#iframe1229").contents().find("body").height()+showittryitheight);
alreadyWriteCode1229 = code1229;
$("#rendering1229").hide();
$("#rendered1229").show();
}
var tRereshRetry2DemoPanel1229 = setInterval(rereshRetry2DemoPanel1229,1000);
var binded1229 = false;
$("textarea#stepcodeTextarea1229").keyup(function(){
if(!binded1229){
$(window).bind('beforeunload',function(){
binded1229 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1229 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1229!=newCode){
// window.frames["iframe1229"].document.write("
");
// window.frames["iframe1229"].document.write(decodeHtml($("textarea#stepcodeTextarea1229").val()));
// window.frames["iframe1229"].document.close();
// $(window.frames["iframe1229"]).load(function(){
// $("#iframe1229").height($("#iframe1229").contents().find("body").height()+showittryitheight);
// });
// code1229 = newCode;
// }
});
$(".tryButton1229").click(function(){
$("#tryDiv1229").show();
$("#stepcodeTextarea1229").focus();
$("#stepcodeTextarea1229").height(200);
$("#iframe1229").height(0);
window.frames["iframe1229"].document.write("
");
window.frames["iframe1229"].document.write(decodeHtml($("textarea#stepcodeTextarea1229").val()));
window.frames["iframe1229"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1229"]).load(function(){
$("#iframe1229").height($("#iframe1229").contents().find("body").height()+showittryitheight);
});
$("#iframe1229").height($("#iframe1229").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1229.focus();
editor1229.setSize(null, "250");
$("#rendering1229").hide();
$("#rendered1229").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 editor1229 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1229"), {
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);
}
}
});
editor1229.on("change",function(doc){
if(!binded1229){
$(window).bind('beforeunload',function(){
binded1229 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1229 = newCode;
$("textarea#stepcodeTextarea1229").val(newCode);
if(alreadyWriteCode1229!=code1229){
lastModifedTime1229 = new Date().getTime();
$("#rendering1229").show();
$("#rendered1229").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1229 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1229.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1229").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|