javascript语句  向 DIV里  写入选中的值比如:选中  dropdownlist 的一个值  ,用javascript就向层中写入 这个值,最好是选中值之后,div 里就显示这个值,不用其他提交操作,就是类似字符串拼接的意思!谢谢 !!急  在线等

解决方案 »

  1.   

    var select1 = document.all.<%= DropdownList1.ClientID %>;
    var selectvalue = select1.options[select1.selectedIndex].value; 
    var selectText= select1.options[select1.selectedIndex].text;
    document.getElementById('divid').innerHTML = selectText;红色是dropdownlist的id,蓝色是div的ID
      

  2.   

     $(function () {
                $("#DropDownList1").change(function () {
                    $("#Div1").html($("#Div1").html() + $(this).val());
                });
            })
      

  3.   

    如是是值就用
    document.getElementById('divid').innerHTML = selectvalue;
      

  4.   

    2楼的是jquery 你需要引入一个 jquery的包
      

  5.   

    dropdownlist 的id aa
    div的id 是bb
    $("#aa").change(function(){
    var _val=$("#aa").find("option[selected]").text();//显示值,如果是value值就直接$("#aa").val();
    $("#bb").html(_val);
    });
      

  6.   

    html代码:<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("<%=ddl1.ClientID %>");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddl1" runat="server" onchange="getthis()">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
            </asp:DropDownList>
            <div id="div1">
            </div>
        </div>
        </form>
    </body>
    </html>
      

  7.   

    自己先顶个 
    document.getElementById("demo").innerText=这个方法 需要 提交才能显示  ,要实时显示的
      

  8.   


    不知道你的实时是什么意思。 就是dropdownlist修改值后的变化吧。
    你用dropdownlist的选中事件去触发js不就实现了么 为什么要提交呢?
      

  9.   

    那就用document.getElementById("demo").innerHTML
      

  10.   

    html代码:<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("<%=ddl1.ClientID %>");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddl1" runat="server" onchange="getthis()">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
            </asp:DropDownList>
            <div id="div1">
            </div>
        </div>
        </form>
    </body>
    </html>
    <body>
        <form id="form1" runat="server">
        
      
        <div>
        
        
        
        
          
                
            <select name="Select1" id="Select1" onchange="getthis()" >
                <option>11111</option>
                <option>22222</option>
            </select>
                
            <div id="div1">
            </div>
        </div>
        </form>
           
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("Select1");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式
     
            }
         
        </script>
    </body>
    这个怎么运行不显示啊  
      

  11.   

    html代码:<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("<%=ddl1.ClientID %>");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddl1" runat="server" onchange="getthis()">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
            </asp:DropDownList>
            <div id="div1">
            </div>
        </div>
        </form>
    </body>
    </html>
    <body>
        <form id="form1" runat="server">
        
      
        <div>
        
        
        
        
          
                
            <select name="Select1" id="Select1" onchange="getthis()" >
                <option>11111</option>
                <option>22222</option>
            </select>
                
            <div id="div1">
            </div>
        </div>
        </form>
           
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("Select1");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式
     
            }
         
        </script>
    </body>
    这个怎么运行不显示啊  
    你的option中 没有value啊 你是想显示其中的text么 两个是不同的概念
      

  12.   

    html代码:<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("<%=ddl1.ClientID %>");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddl1" runat="server" onchange="getthis()">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
            </asp:DropDownList>
            <div id="div1">
            </div>
        </div>
        </form>
    </body>
    </html>
    <body>
        <form id="form1" runat="server">
        
      
        <div>
        
        
        
        
          
                
            <select name="Select1" id="Select1" onchange="getthis()" >
                <option>11111</option>
                <option>22222</option>
            </select>
                
            <div id="div1">
            </div>
        </div>
        </form>
           
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("Select1");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式
     
            }
         
        </script>
    </body>
    这个怎么运行不显示啊  
    你的option中 没有value啊 你是想显示其中的text么 两个是不同的概念有什么办法显示其中的text吗?  就是 <option>11111</option>  中的值
      

  13.   

    html代码:<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("<%=ddl1.ClientID %>");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddl1" runat="server" onchange="getthis()">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
                <asp:ListItem Value="5">5</asp:ListItem>
            </asp:DropDownList>
            <div id="div1">
            </div>
        </div>
        </form>
    </body>
    </html>
    <body>
        <form id="form1" runat="server">
        
      
        <div>
        
        
        
        
          
                
            <select name="Select1" id="Select1" onchange="getthis()" >
                <option>11111</option>
                <option>22222</option>
            </select>
                
            <div id="div1">
            </div>
        </div>
        </form>
           
        <script type="text/javascript">
            function getthis() {
                var rtl = document.getElementById("Select1");
                var s = rtl.options[rtl.selectedIndex].value;
                document.getElementById("div1").innerHTML = document.getElementById("div1").innerHTML + s;//没用jquery就用这种方式
     
            }
         
        </script>
    </body>
    这个怎么运行不显示啊  
    你的option中 没有value啊 你是想显示其中的text么 两个是不同的概念有什么办法显示其中的text吗?  就是 <option>11111</option>  中的值
    var s = rtl.options[rtl.selectedIndex].value;中的value改为text 。但是onchange这个事件 只是在select选项中的值改变才触发 比如你之前选择的是11111现在又点一次11111 那么就不会触发了 但是你如果现在点22222那么就会触发