with(document.all("idSel"))var sValue=options[selectedIndex].value;//等同于var sValue=document.all("idSel").options[selectedIndex].value;with没学过吗?
with的用法在各种语言中大同小异吧?

解决方案 »

  1.   

     但是我把with(document.all("idSel"))var sValue=options[selectedIndex].value;
     改为:var sValue=document.all("idSel").options[selectedIndex].value;
     就出现错误:'document.all(...).options[...].value'为空或不是对象..
      

  2.   


    var sValue=document.all("idSel").options[document.all("idSel").selectedIndex].value;
      

  3.   

     但是我把with(document.all("idSel"))var   sValue=options[selectedIndex].value; 
      改为:var   sValue=document.all("idSel").options[selectedIndex].value; 
      就出现错误:'document.all(...).options[...].value'为空或不是对象.. 
    -------------------------------------------------------------------
    selectedIndex是idSel滴属性,用with时没问题,瞎改当然就错了!要短滴这么写就行了,L@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="Gao YiXiang" />
        <meta name="email" content="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
    <style>
    #idDIV{width:100%;height:80px;background-color:#FFD700;padding:4px;font-family:verdana,tahoma;font-weight:bold;}
    </style>
    </head>
    <body>
        <script>
    function rdl_change(e)
    {
        var oDiv=document.all("idDiv");
        oDiv.style.fontVariant=document.all("idSel").value;
    }
    </script><div   id=idDIV> Every   man   dies   ,   Not   every   man   really   lives   . </div>
    <br>
    <select   id="idSel"   onchange="rdl_change();">
    <option   value="normal"> ---font-variant---
    <option   value="normal"> normal
    <option   value="small-caps"> small-caps
    </select>
    <br>
    </body>
    </html>