how2j.cn


工具版本兼容问题
<button></button>即按钮标签
与<input type="button">不同的是,<button>标签功能更为丰富

按钮标签里的内容可以是文字也可以是图像

如果button的type=“submit” ,那么它就具备提交form的功能

示例 1 : button里是文字   
示例 2 : button里是图片   
示例 3 : 提交数据   

示例 1 :

button里是文字

"); window.frames["iframe_show375"].document.write(decodeHtml($("textarea#stepcodeTextarea375").val())); window.frames["iframe_show375"].document.close(); $(window.frames["iframe_show375"]).load(function(){ $("#iframe_show375").height($("#iframe_show375").contents().find("body").height()+showittryitheight); }); $("#iframe_show375").height($("#iframe_show375").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<button>按钮</button>
<button>按钮</button>
"); window.frames["iframe375"].document.write(decodeHtml(code375)); window.frames["iframe375"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe375"]).load(function(){ $("#iframe375").height($("#iframe375").contents().find("body").height()+showittryitheight); }); $("#iframe375").height($("#iframe375").contents().find("body").height()+showittryitheight); alreadyWriteCode375 = code375; $("#rendering375").hide(); $("#rendered375").show(); } var tRereshRetry2DemoPanel375 = setInterval(rereshRetry2DemoPanel375,1000); var binded375 = false; $("textarea#stepcodeTextarea375").keyup(function(){ if(!binded375){ $(window).bind('beforeunload',function(){ binded375 = true; return "xxxx"; }); } var newCode = $(this).val() code375 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code375!=newCode){ // window.frames["iframe375"].document.write("
"); // window.frames["iframe375"].document.write(decodeHtml($("textarea#stepcodeTextarea375").val())); // window.frames["iframe375"].document.close(); // $(window.frames["iframe375"]).load(function(){ // $("#iframe375").height($("#iframe375").contents().find("body").height()+showittryitheight); // }); // code375 = newCode; // } }); $(".tryButton375").click(function(){ $("#tryDiv375").show(); $("#stepcodeTextarea375").focus(); $("#stepcodeTextarea375").height(200); $("#iframe375").height(0); window.frames["iframe375"].document.write("
"); window.frames["iframe375"].document.write(decodeHtml($("textarea#stepcodeTextarea375").val())); window.frames["iframe375"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe375"]).load(function(){ $("#iframe375").height($("#iframe375").contents().find("body").height()+showittryitheight); }); $("#iframe375").height($("#iframe375").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor375.focus(); editor375.setSize(null, "250"); $("#rendering375").hide(); $("#rendered375").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 editor375 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea375"), { 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); } } }); editor375.on("change",function(doc){ if(!binded375){ $(window).bind('beforeunload',function(){ binded375 = true; return "xxxx"; }); } var newCode = doc.getValue(); code375 = newCode; $("textarea#stepcodeTextarea375").val(newCode); if(alreadyWriteCode375!=code375){ lastModifedTime375 = new Date().getTime(); $("#rendering375").show(); $("#rendered375").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor375 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor375.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv375").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

button里是图片

"); window.frames["iframe_show376"].document.write(decodeHtml($("textarea#stepcodeTextarea376").val())); window.frames["iframe_show376"].document.close(); $(window.frames["iframe_show376"]).load(function(){ $("#iframe_show376").height($("#iframe_show376").contents().find("body").height()+showittryitheight); }); $("#iframe_show376").height($("#iframe_show376").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<button><img src="http://127.0.0.1/example.gif"/></button>
<button><img src="http://127.0.0.1/example.gif"/></button>
"); window.frames["iframe376"].document.write(decodeHtml(code376)); window.frames["iframe376"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe376"]).load(function(){ $("#iframe376").height($("#iframe376").contents().find("body").height()+showittryitheight); }); $("#iframe376").height($("#iframe376").contents().find("body").height()+showittryitheight); alreadyWriteCode376 = code376; $("#rendering376").hide(); $("#rendered376").show(); } var tRereshRetry2DemoPanel376 = setInterval(rereshRetry2DemoPanel376,1000); var binded376 = false; $("textarea#stepcodeTextarea376").keyup(function(){ if(!binded376){ $(window).bind('beforeunload',function(){ binded376 = true; return "xxxx"; }); } var newCode = $(this).val() code376 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code376!=newCode){ // window.frames["iframe376"].document.write("
"); // window.frames["iframe376"].document.write(decodeHtml($("textarea#stepcodeTextarea376").val())); // window.frames["iframe376"].document.close(); // $(window.frames["iframe376"]).load(function(){ // $("#iframe376").height($("#iframe376").contents().find("body").height()+showittryitheight); // }); // code376 = newCode; // } }); $(".tryButton376").click(function(){ $("#tryDiv376").show(); $("#stepcodeTextarea376").focus(); $("#stepcodeTextarea376").height(200); $("#iframe376").height(0); window.frames["iframe376"].document.write("
"); window.frames["iframe376"].document.write(decodeHtml($("textarea#stepcodeTextarea376").val())); window.frames["iframe376"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe376"]).load(function(){ $("#iframe376").height($("#iframe376").contents().find("body").height()+showittryitheight); }); $("#iframe376").height($("#iframe376").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor376.focus(); editor376.setSize(null, "250"); $("#rendering376").hide(); $("#rendered376").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 editor376 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea376"), { 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); } } }); editor376.on("change",function(doc){ if(!binded376){ $(window).bind('beforeunload',function(){ binded376 = true; return "xxxx"; }); } var newCode = doc.getValue(); code376 = newCode; $("textarea#stepcodeTextarea376").val(newCode); if(alreadyWriteCode376!=code376){ lastModifedTime376 = new Date().getTime(); $("#rendering376").show(); $("#rendered376").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor376 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor376.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv376").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

提交数据

设置type="submit"
IE下button的type的默认值为button不具备提交功能
其他浏览器type的默认值是submit
"); window.frames["iframe_show377"].document.write(decodeHtml($("textarea#stepcodeTextarea377").val())); window.frames["iframe_show377"].document.close(); $(window.frames["iframe_show377"]).load(function(){ $("#iframe_show377").height($("#iframe_show377").contents().find("body").height()+showittryitheight); }); $("#iframe_show377").height($("#iframe_show377").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<form action="/study/login.jsp"> 账号:<input type="text" name="name"> <br/> 密码:<input type="password" name="password" > <br/> <button type="submit">登陆</button> </form>
<form action="/study/login.jsp">
账号:<input type="text" name="name"> <br/>
密码:<input type="password" name="password" > <br/>

<button type="submit">登陆</button>

</form>
"); window.frames["iframe377"].document.write(decodeHtml(code377)); window.frames["iframe377"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe377"]).load(function(){ $("#iframe377").height($("#iframe377").contents().find("body").height()+showittryitheight); }); $("#iframe377").height($("#iframe377").contents().find("body").height()+showittryitheight); alreadyWriteCode377 = code377; $("#rendering377").hide(); $("#rendered377").show(); } var tRereshRetry2DemoPanel377 = setInterval(rereshRetry2DemoPanel377,1000); var binded377 = false; $("textarea#stepcodeTextarea377").keyup(function(){ if(!binded377){ $(window).bind('beforeunload',function(){ binded377 = true; return "xxxx"; }); } var newCode = $(this).val() code377 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code377!=newCode){ // window.frames["iframe377"].document.write("
"); // window.frames["iframe377"].document.write(decodeHtml($("textarea#stepcodeTextarea377").val())); // window.frames["iframe377"].document.close(); // $(window.frames["iframe377"]).load(function(){ // $("#iframe377").height($("#iframe377").contents().find("body").height()+showittryitheight); // }); // code377 = newCode; // } }); $(".tryButton377").click(function(){ $("#tryDiv377").show(); $("#stepcodeTextarea377").focus(); $("#stepcodeTextarea377").height(200); $("#iframe377").height(0); window.frames["iframe377"].document.write("
"); window.frames["iframe377"].document.write(decodeHtml($("textarea#stepcodeTextarea377").val())); window.frames["iframe377"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe377"]).load(function(){ $("#iframe377").height($("#iframe377").contents().find("body").height()+showittryitheight); }); $("#iframe377").height($("#iframe377").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor377.focus(); editor377.setSize(null, "250"); $("#rendering377").hide(); $("#rendered377").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 editor377 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea377"), { 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); } } }); editor377.on("change",function(doc){ if(!binded377){ $(window).bind('beforeunload',function(){ binded377 = true; return "xxxx"; }); } var newCode = doc.getValue(); code377 = newCode; $("textarea#stepcodeTextarea377").val(newCode); if(alreadyWriteCode377!=code377){ lastModifedTime377 = new Date().getTime(); $("#rendering377").show(); $("#rendered377").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor377 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor377.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv377").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

上传截图