how2j.cn


工具版本兼容问题
<a>标签即用来显示超链

完整元素是

<a href="跳转到的页面地址">超链显示文本</a>

示例 1 : 超链   
示例 2 : 在新的页面打开超链   
示例 3 : 超链上的提示文字   
示例 4 : 使用图片作为超链   

示例 1 :

超链

"); window.frames["iframe_show309"].document.write(decodeHtml($("textarea#stepcodeTextarea309").val())); window.frames["iframe_show309"].document.close(); $(window.frames["iframe_show309"]).load(function(){ $("#iframe_show309").height($("#iframe_show309").contents().find("body").height()+showittryitheight); }); $("#iframe_show309").height($("#iframe_show309").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<a href="http://www.12306.com">12306</a>
<a href="http://www.12306.com">12306</a>
"); window.frames["iframe309"].document.write(decodeHtml(code309)); window.frames["iframe309"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe309"]).load(function(){ $("#iframe309").height($("#iframe309").contents().find("body").height()+showittryitheight); }); $("#iframe309").height($("#iframe309").contents().find("body").height()+showittryitheight); alreadyWriteCode309 = code309; $("#rendering309").hide(); $("#rendered309").show(); } var tRereshRetry2DemoPanel309 = setInterval(rereshRetry2DemoPanel309,1000); var binded309 = false; $("textarea#stepcodeTextarea309").keyup(function(){ if(!binded309){ $(window).bind('beforeunload',function(){ binded309 = true; return "xxxx"; }); } var newCode = $(this).val() code309 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code309!=newCode){ // window.frames["iframe309"].document.write("
"); // window.frames["iframe309"].document.write(decodeHtml($("textarea#stepcodeTextarea309").val())); // window.frames["iframe309"].document.close(); // $(window.frames["iframe309"]).load(function(){ // $("#iframe309").height($("#iframe309").contents().find("body").height()+showittryitheight); // }); // code309 = newCode; // } }); $(".tryButton309").click(function(){ $("#tryDiv309").show(); $("#stepcodeTextarea309").focus(); $("#stepcodeTextarea309").height(200); $("#iframe309").height(0); window.frames["iframe309"].document.write("
"); window.frames["iframe309"].document.write(decodeHtml($("textarea#stepcodeTextarea309").val())); window.frames["iframe309"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe309"]).load(function(){ $("#iframe309").height($("#iframe309").contents().find("body").height()+showittryitheight); }); $("#iframe309").height($("#iframe309").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor309.focus(); editor309.setSize(null, "250"); $("#rendering309").hide(); $("#rendered309").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 editor309 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea309"), { 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); } } }); editor309.on("change",function(doc){ if(!binded309){ $(window).bind('beforeunload',function(){ binded309 = true; return "xxxx"; }); } var newCode = doc.getValue(); code309 = newCode; $("textarea#stepcodeTextarea309").val(newCode); if(alreadyWriteCode309!=code309){ lastModifedTime309 = new Date().getTime(); $("#rendering309").show(); $("#rendered309").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor309 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor309.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv309").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 2 :

在新的页面打开超链

新增属性target
"); window.frames["iframe_show310"].document.write(decodeHtml($("textarea#stepcodeTextarea310").val())); window.frames["iframe_show310"].document.close(); $(window.frames["iframe_show310"]).load(function(){ $("#iframe_show310").height($("#iframe_show310").contents().find("body").height()+showittryitheight); }); $("#iframe_show310").height($("#iframe_show310").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<a href="http://www.12306.com" target="_blank">http://www.12306.com</a>
<a href="http://www.12306.com" target="_blank">http://www.12306.com</a>
"); window.frames["iframe310"].document.write(decodeHtml(code310)); window.frames["iframe310"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe310"]).load(function(){ $("#iframe310").height($("#iframe310").contents().find("body").height()+showittryitheight); }); $("#iframe310").height($("#iframe310").contents().find("body").height()+showittryitheight); alreadyWriteCode310 = code310; $("#rendering310").hide(); $("#rendered310").show(); } var tRereshRetry2DemoPanel310 = setInterval(rereshRetry2DemoPanel310,1000); var binded310 = false; $("textarea#stepcodeTextarea310").keyup(function(){ if(!binded310){ $(window).bind('beforeunload',function(){ binded310 = true; return "xxxx"; }); } var newCode = $(this).val() code310 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code310!=newCode){ // window.frames["iframe310"].document.write("
"); // window.frames["iframe310"].document.write(decodeHtml($("textarea#stepcodeTextarea310").val())); // window.frames["iframe310"].document.close(); // $(window.frames["iframe310"]).load(function(){ // $("#iframe310").height($("#iframe310").contents().find("body").height()+showittryitheight); // }); // code310 = newCode; // } }); $(".tryButton310").click(function(){ $("#tryDiv310").show(); $("#stepcodeTextarea310").focus(); $("#stepcodeTextarea310").height(200); $("#iframe310").height(0); window.frames["iframe310"].document.write("
"); window.frames["iframe310"].document.write(decodeHtml($("textarea#stepcodeTextarea310").val())); window.frames["iframe310"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe310"]).load(function(){ $("#iframe310").height($("#iframe310").contents().find("body").height()+showittryitheight); }); $("#iframe310").height($("#iframe310").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor310.focus(); editor310.setSize(null, "250"); $("#rendering310").hide(); $("#rendered310").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 editor310 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea310"), { 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); } } }); editor310.on("change",function(doc){ if(!binded310){ $(window).bind('beforeunload',function(){ binded310 = true; return "xxxx"; }); } var newCode = doc.getValue(); code310 = newCode; $("textarea#stepcodeTextarea310").val(newCode); if(alreadyWriteCode310!=code310){ lastModifedTime310 = new Date().getTime(); $("#rendering310").show(); $("#rendered310").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor310 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor310.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv310").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 3 :

超链上的提示文字

当鼠标放在超链上的时候,就会弹出提示文字
"); window.frames["iframe_show337"].document.write(decodeHtml($("textarea#stepcodeTextarea337").val())); window.frames["iframe_show337"].document.close(); $(window.frames["iframe_show337"]).load(function(){ $("#iframe_show337").height($("#iframe_show337").contents().find("body").height()+showittryitheight); }); $("#iframe_show337").height($("#iframe_show337").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<a href="http://www.12306.com" title="跳转到http://www.12306.com">www.12306.com</a>
<a href="http://www.12306.com" title="跳转到http://www.12306.com">www.12306.com</a>
"); window.frames["iframe337"].document.write(decodeHtml(code337)); window.frames["iframe337"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe337"]).load(function(){ $("#iframe337").height($("#iframe337").contents().find("body").height()+showittryitheight); }); $("#iframe337").height($("#iframe337").contents().find("body").height()+showittryitheight); alreadyWriteCode337 = code337; $("#rendering337").hide(); $("#rendered337").show(); } var tRereshRetry2DemoPanel337 = setInterval(rereshRetry2DemoPanel337,1000); var binded337 = false; $("textarea#stepcodeTextarea337").keyup(function(){ if(!binded337){ $(window).bind('beforeunload',function(){ binded337 = true; return "xxxx"; }); } var newCode = $(this).val() code337 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code337!=newCode){ // window.frames["iframe337"].document.write("
"); // window.frames["iframe337"].document.write(decodeHtml($("textarea#stepcodeTextarea337").val())); // window.frames["iframe337"].document.close(); // $(window.frames["iframe337"]).load(function(){ // $("#iframe337").height($("#iframe337").contents().find("body").height()+showittryitheight); // }); // code337 = newCode; // } }); $(".tryButton337").click(function(){ $("#tryDiv337").show(); $("#stepcodeTextarea337").focus(); $("#stepcodeTextarea337").height(200); $("#iframe337").height(0); window.frames["iframe337"].document.write("
"); window.frames["iframe337"].document.write(decodeHtml($("textarea#stepcodeTextarea337").val())); window.frames["iframe337"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe337"]).load(function(){ $("#iframe337").height($("#iframe337").contents().find("body").height()+showittryitheight); }); $("#iframe337").height($("#iframe337").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor337.focus(); editor337.setSize(null, "250"); $("#rendering337").hide(); $("#rendered337").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 editor337 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea337"), { 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); } } }); editor337.on("change",function(doc){ if(!binded337){ $(window).bind('beforeunload',function(){ binded337 = true; return "xxxx"; }); } var newCode = doc.getValue(); code337 = newCode; $("textarea#stepcodeTextarea337").val(newCode); if(alreadyWriteCode337!=code337){ lastModifedTime337 = new Date().getTime(); $("#rendering337").show(); $("#rendered337").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor337 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor337.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv337").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 4 :

使用图片作为超链

"); window.frames["iframe_show336"].document.write(decodeHtml($("textarea#stepcodeTextarea336").val())); window.frames["iframe_show336"].document.close(); $(window.frames["iframe_show336"]).load(function(){ $("#iframe_show336").height($("#iframe_show336").contents().find("body").height()+showittryitheight); }); $("#iframe_show336").height($("#iframe_show336").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<a href="http://www.12306.com"> <img src="http://127.0.0.1/example.gif"/> </a>
<a href="http://www.12306.com">
<img src="http://127.0.0.1/example.gif"/>
</a>
"); window.frames["iframe336"].document.write(decodeHtml(code336)); window.frames["iframe336"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe336"]).load(function(){ $("#iframe336").height($("#iframe336").contents().find("body").height()+showittryitheight); }); $("#iframe336").height($("#iframe336").contents().find("body").height()+showittryitheight); alreadyWriteCode336 = code336; $("#rendering336").hide(); $("#rendered336").show(); } var tRereshRetry2DemoPanel336 = setInterval(rereshRetry2DemoPanel336,1000); var binded336 = false; $("textarea#stepcodeTextarea336").keyup(function(){ if(!binded336){ $(window).bind('beforeunload',function(){ binded336 = true; return "xxxx"; }); } var newCode = $(this).val() code336 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code336!=newCode){ // window.frames["iframe336"].document.write("
"); // window.frames["iframe336"].document.write(decodeHtml($("textarea#stepcodeTextarea336").val())); // window.frames["iframe336"].document.close(); // $(window.frames["iframe336"]).load(function(){ // $("#iframe336").height($("#iframe336").contents().find("body").height()+showittryitheight); // }); // code336 = newCode; // } }); $(".tryButton336").click(function(){ $("#tryDiv336").show(); $("#stepcodeTextarea336").focus(); $("#stepcodeTextarea336").height(200); $("#iframe336").height(0); window.frames["iframe336"].document.write("
"); window.frames["iframe336"].document.write(decodeHtml($("textarea#stepcodeTextarea336").val())); window.frames["iframe336"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe336"]).load(function(){ $("#iframe336").height($("#iframe336").contents().find("body").height()+showittryitheight); }); $("#iframe336").height($("#iframe336").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor336.focus(); editor336.setSize(null, "250"); $("#rendering336").hide(); $("#rendered336").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 editor336 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea336"), { 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); } } }); editor336.on("change",function(doc){ if(!binded336){ $(window).bind('beforeunload',function(){ binded336 = true; return "xxxx"; }); } var newCode = doc.getValue(); code336 = newCode; $("textarea#stepcodeTextarea336").val(newCode); if(alreadyWriteCode336!=code336){ lastModifedTime336 = new Date().getTime(); $("#rendering336").show(); $("#rendered336").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor336 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor336.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv336").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


关于 前端部分-HTML-超链 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图