在html里没有直接的控件可用,模拟实现
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0060)http://www.51javascript.net/free/Messages/demo/me11-demo.htm -->
<HTML><HEAD><TITLE>可编辑菜单</TITLE>
<META content="提供知识指南,相关参考资料,js 编辑器,即免费脚本" name=description>
<META content=指南,参考资料,技术论坛,脚本 name=keywords>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<SCRIPT language=JavaScript>
<!-- Begin
var o = null;
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function beginEditing(menu) {
finish();
if(menu[menu.selectedIndex].value != "read-only") {
o = new Object();
o.editOption = menu[menu.selectedIndex];
o.editOption.old = o.editOption.text;
o.editOption.text = "_";
menu.blur();
window.focus();
document.onkeypress = keyPressHandler;
}
function keyPressHandler(e){
var option = o.editOption;
var keyCode = (isNN) ? e.which : event.keyCode;
if(keyCode == 8 || keyCode == 37)
option.text = option.text.substring(0,option.text.length-2) + "_";
else if (keyCode == 13) {
finish();
} else
option.text = option.text.substring(0,option.text.length-1) + String.fromCharCode(keyCode) + "_";
status = keyCode;
}
function finish() {
if(o != null) {
option = o.editOption;
if(option.text.length > 1)
option.text = option.text.substring(0,option.text.length-1);
else
option.text = option.old;
document.onkeypress = null;
o = null;
      }
   }
}
//  End -->
</SCRIPT><META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>

解决方案 »

  1.   

    应该在何处调用beginEditing(menu)?其中的menu是不是select控件的名称?
      

  2.   

    http://lucky.myrice.com/temp/combobox.htm猛子E章 的网站上就有 /
      

  3.   

    http://lucky.myrice.com/temp/combobox.htm确实可以实现,可我看到的原码是:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0041)http://lucky.myrice.com/temp/combobox.htm -->
    <HTML><HEAD>
    <META content="text/html; charset=big5" http-equiv=Content-Type>
    <SCRIPT src="combobox.files/yCodelib.js"></SCRIPT><SCRIPT>x956203888516();</SCRIPT><SCRIPT src="combobox.files/yCode_combo_box.js"></SCRIPT><META content="MSHTML 5.00.3315.2870" name=GENERATOR></HEAD>
    <BODY onload=x956203888444(); onresize=x956203888510();>
    <P>&Ccedil;&euml;&Ecirc;&auml;&Egrave;&euml;: <SELECT id=tryComboBoxID 
    onchange="if (x956203888447!=null) {x956203888447.x956203888455();}" 
    onresize="if (x956203888447!=null) {x956203888447.x956203888454();}" 
    style="POSITION: absolute"> <OPTION selected 
      [email protected]>[email protected]</OPTION> <OPTION 
      [email protected]>[email protected]</OPTION> <OPTION 
      [email protected]>[email protected]</OPTION></SELECT> <BR><BR><BR><INPUT id=getTryValueButtonID name=retrieve onclick="alert('&Auml;&atilde;&micro;&Auml;&Ouml;&micro;&Ecirc;&Ccedil;&pound;&ordm; \'' + x956203888447.x956203888453() + '\'');" type=button value=&micro;&Atilde;&micro;&frac12;&Ouml;&micro;> 
    </P>
    <SCRIPT> 
    var x956203888447; 
    function x956203888444() { 
    x956203888447 = new x956203888449("tryComboBoxID", "x956203888447"); 
    x956203888447.x956203888460(-1); 
    x956203888447.focus(); 

    </SCRIPT>
    </BODY></HTML>sduwjr(流星) 难道你那里可以看得清原码吗?