how2j.cn


工具版本兼容问题
<select> 即下拉列表
需要配合<option>使用

示例 1 : 下拉列表   
示例 2 : 设置高度   
示例 3 : 设置可以多选   
示例 4 : 默认选中   

示例 1 :

下拉列表

"); window.frames["iframe_show366"].document.write(decodeHtml($("textarea#stepcodeTextarea366").val())); window.frames["iframe_show366"].document.close(); $(window.frames["iframe_show366"]).load(function(){ $("#iframe_show366").height($("#iframe_show366").contents().find("body").height()+showittryitheight); }); $("#iframe_show366").height($("#iframe_show366").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<select > <option >苍老师</option> <option >高树玛利亚</option> <option >遥美</option> </select>
<select >
 <option >苍老师</option>
 <option >高树玛利亚</option>
 <option >遥美</option>
</select>
"); window.frames["iframe366"].document.write(decodeHtml(code366)); window.frames["iframe366"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe366"]).load(function(){ $("#iframe366").height($("#iframe366").contents().find("body").height()+showittryitheight); }); $("#iframe366").height($("#iframe366").contents().find("body").height()+showittryitheight); alreadyWriteCode366 = code366; $("#rendering366").hide(); $("#rendered366").show(); } var tRereshRetry2DemoPanel366 = setInterval(rereshRetry2DemoPanel366,1000); var binded366 = false; $("textarea#stepcodeTextarea366").keyup(function(){ if(!binded366){ $(window).bind('beforeunload',function(){ binded366 = true; return "xxxx"; }); } var newCode = $(this).val() code366 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code366!=newCode){ // window.frames["iframe366"].document.write("
"); // window.frames["iframe366"].document.write(decodeHtml($("textarea#stepcodeTextarea366").val())); // window.frames["iframe366"].document.close(); // $(window.frames["iframe366"]).load(function(){ // $("#iframe366").height($("#iframe366").contents().find("body").height()+showittryitheight); // }); // code366 = newCode; // } }); $(".tryButton366").click(function(){ $("#tryDiv366").show(); $("#stepcodeTextarea366").focus(); $("#stepcodeTextarea366").height(200); $("#iframe366").height(0); window.frames["iframe366"].document.write("
"); window.frames["iframe366"].document.write(decodeHtml($("textarea#stepcodeTextarea366").val())); window.frames["iframe366"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe366"]).load(function(){ $("#iframe366").height($("#iframe366").contents().find("body").height()+showittryitheight); }); $("#iframe366").height($("#iframe366").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor366.focus(); editor366.setSize(null, "250"); $("#rendering366").hide(); $("#rendered366").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 editor366 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea366"), { 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); } } }); editor366.on("change",function(doc){ if(!binded366){ $(window).bind('beforeunload',function(){ binded366 = true; return "xxxx"; }); } var newCode = doc.getValue(); code366 = newCode; $("textarea#stepcodeTextarea366").val(newCode); if(alreadyWriteCode366!=code366){ lastModifedTime366 = new Date().getTime(); $("#rendering366").show(); $("#rendered366").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor366 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor366.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv366").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

设置高度

使用属性size
"); window.frames["iframe_show367"].document.write(decodeHtml($("textarea#stepcodeTextarea367").val())); window.frames["iframe_show367"].document.close(); $(window.frames["iframe_show367"]).load(function(){ $("#iframe_show367").height($("#iframe_show367").contents().find("body").height()+showittryitheight); }); $("#iframe_show367").height($("#iframe_show367").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<select size="2"> <option >苍老师</option> <option >高树玛利亚</option> <option >遥美</option> </select>
<select  size="2">
 <option >苍老师</option>
 <option >高树玛利亚</option>
 <option >遥美</option>
</select>
"); window.frames["iframe367"].document.write(decodeHtml(code367)); window.frames["iframe367"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe367"]).load(function(){ $("#iframe367").height($("#iframe367").contents().find("body").height()+showittryitheight); }); $("#iframe367").height($("#iframe367").contents().find("body").height()+showittryitheight); alreadyWriteCode367 = code367; $("#rendering367").hide(); $("#rendered367").show(); } var tRereshRetry2DemoPanel367 = setInterval(rereshRetry2DemoPanel367,1000); var binded367 = false; $("textarea#stepcodeTextarea367").keyup(function(){ if(!binded367){ $(window).bind('beforeunload',function(){ binded367 = true; return "xxxx"; }); } var newCode = $(this).val() code367 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code367!=newCode){ // window.frames["iframe367"].document.write("
"); // window.frames["iframe367"].document.write(decodeHtml($("textarea#stepcodeTextarea367").val())); // window.frames["iframe367"].document.close(); // $(window.frames["iframe367"]).load(function(){ // $("#iframe367").height($("#iframe367").contents().find("body").height()+showittryitheight); // }); // code367 = newCode; // } }); $(".tryButton367").click(function(){ $("#tryDiv367").show(); $("#stepcodeTextarea367").focus(); $("#stepcodeTextarea367").height(200); $("#iframe367").height(0); window.frames["iframe367"].document.write("
"); window.frames["iframe367"].document.write(decodeHtml($("textarea#stepcodeTextarea367").val())); window.frames["iframe367"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe367"]).load(function(){ $("#iframe367").height($("#iframe367").contents().find("body").height()+showittryitheight); }); $("#iframe367").height($("#iframe367").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor367.focus(); editor367.setSize(null, "250"); $("#rendering367").hide(); $("#rendered367").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 editor367 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea367"), { 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); } } }); editor367.on("change",function(doc){ if(!binded367){ $(window).bind('beforeunload',function(){ binded367 = true; return "xxxx"; }); } var newCode = doc.getValue(); code367 = newCode; $("textarea#stepcodeTextarea367").val(newCode); if(alreadyWriteCode367!=code367){ lastModifedTime367 = new Date().getTime(); $("#rendering367").show(); $("#rendered367").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor367 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor367.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv367").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

设置可以多选

使用ctrl或者shift进行多选
"); window.frames["iframe_show368"].document.write(decodeHtml($("textarea#stepcodeTextarea368").val())); window.frames["iframe_show368"].document.close(); $(window.frames["iframe_show368"]).load(function(){ $("#iframe_show368").height($("#iframe_show368").contents().find("body").height()+showittryitheight); }); $("#iframe_show368").height($("#iframe_show368").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<select size="3" multiple="multiple"> <option >苍老师</option> <option >高树玛利亚</option> <option >遥美</option> </select>
<select size="3" multiple="multiple">
 <option >苍老师</option>
 <option >高树玛利亚</option>
 <option >遥美</option>
</select>
"); window.frames["iframe368"].document.write(decodeHtml(code368)); window.frames["iframe368"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe368"]).load(function(){ $("#iframe368").height($("#iframe368").contents().find("body").height()+showittryitheight); }); $("#iframe368").height($("#iframe368").contents().find("body").height()+showittryitheight); alreadyWriteCode368 = code368; $("#rendering368").hide(); $("#rendered368").show(); } var tRereshRetry2DemoPanel368 = setInterval(rereshRetry2DemoPanel368,1000); var binded368 = false; $("textarea#stepcodeTextarea368").keyup(function(){ if(!binded368){ $(window).bind('beforeunload',function(){ binded368 = true; return "xxxx"; }); } var newCode = $(this).val() code368 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code368!=newCode){ // window.frames["iframe368"].document.write("
"); // window.frames["iframe368"].document.write(decodeHtml($("textarea#stepcodeTextarea368").val())); // window.frames["iframe368"].document.close(); // $(window.frames["iframe368"]).load(function(){ // $("#iframe368").height($("#iframe368").contents().find("body").height()+showittryitheight); // }); // code368 = newCode; // } }); $(".tryButton368").click(function(){ $("#tryDiv368").show(); $("#stepcodeTextarea368").focus(); $("#stepcodeTextarea368").height(200); $("#iframe368").height(0); window.frames["iframe368"].document.write("
"); window.frames["iframe368"].document.write(decodeHtml($("textarea#stepcodeTextarea368").val())); window.frames["iframe368"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe368"]).load(function(){ $("#iframe368").height($("#iframe368").contents().find("body").height()+showittryitheight); }); $("#iframe368").height($("#iframe368").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor368.focus(); editor368.setSize(null, "250"); $("#rendering368").hide(); $("#rendered368").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 editor368 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea368"), { 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); } } }); editor368.on("change",function(doc){ if(!binded368){ $(window).bind('beforeunload',function(){ binded368 = true; return "xxxx"; }); } var newCode = doc.getValue(); code368 = newCode; $("textarea#stepcodeTextarea368").val(newCode); if(alreadyWriteCode368!=code368){ lastModifedTime368 = new Date().getTime(); $("#rendering368").show(); $("#rendered368").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor368 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor368.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv368").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

默认选中

对option元素设置selected="selected" 属性
"); window.frames["iframe_show369"].document.write(decodeHtml($("textarea#stepcodeTextarea369").val())); window.frames["iframe_show369"].document.close(); $(window.frames["iframe_show369"]).load(function(){ $("#iframe_show369").height($("#iframe_show369").contents().find("body").height()+showittryitheight); }); $("#iframe_show369").height($("#iframe_show369").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<select size="3" multiple="multiple"> <option >苍老师</option> <option selected="selected">高树玛利亚</option> <option selected="selected">遥美</option> </select>
<select size="3" multiple="multiple">
 <option >苍老师</option>
 <option selected="selected">高树玛利亚</option>
 <option selected="selected">遥美</option>
</select>
"); window.frames["iframe369"].document.write(decodeHtml(code369)); window.frames["iframe369"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe369"]).load(function(){ $("#iframe369").height($("#iframe369").contents().find("body").height()+showittryitheight); }); $("#iframe369").height($("#iframe369").contents().find("body").height()+showittryitheight); alreadyWriteCode369 = code369; $("#rendering369").hide(); $("#rendered369").show(); } var tRereshRetry2DemoPanel369 = setInterval(rereshRetry2DemoPanel369,1000); var binded369 = false; $("textarea#stepcodeTextarea369").keyup(function(){ if(!binded369){ $(window).bind('beforeunload',function(){ binded369 = true; return "xxxx"; }); } var newCode = $(this).val() code369 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code369!=newCode){ // window.frames["iframe369"].document.write("
"); // window.frames["iframe369"].document.write(decodeHtml($("textarea#stepcodeTextarea369").val())); // window.frames["iframe369"].document.close(); // $(window.frames["iframe369"]).load(function(){ // $("#iframe369").height($("#iframe369").contents().find("body").height()+showittryitheight); // }); // code369 = newCode; // } }); $(".tryButton369").click(function(){ $("#tryDiv369").show(); $("#stepcodeTextarea369").focus(); $("#stepcodeTextarea369").height(200); $("#iframe369").height(0); window.frames["iframe369"].document.write("
"); window.frames["iframe369"].document.write(decodeHtml($("textarea#stepcodeTextarea369").val())); window.frames["iframe369"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe369"]).load(function(){ $("#iframe369").height($("#iframe369").contents().find("body").height()+showittryitheight); }); $("#iframe369").height($("#iframe369").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor369.focus(); editor369.setSize(null, "250"); $("#rendering369").hide(); $("#rendered369").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 editor369 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea369"), { 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); } } }); editor369.on("change",function(doc){ if(!binded369){ $(window).bind('beforeunload',function(){ binded369 = true; return "xxxx"; }); } var newCode = doc.getValue(); code369 = newCode; $("textarea#stepcodeTextarea369").val(newCode); if(alreadyWriteCode369!=code369){ lastModifedTime369 = new Date().getTime(); $("#rendering369").show(); $("#rendered369").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor369 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor369.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv369").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

上传截图