我的web页面有个dropdownlist,我想把dropdownlist所选的值取出来,给javascript中的一个变量,不知道怎么才能给这个变量,急死了!希望大家帮忙!

解决方案 »

  1.   

    DropDownList.SelectedItem.Value 属性
      

  2.   

    你得用一个事件触发这个函数。如:Button
      

  3.   

    string svalue=DropDownList.SelectedItem.Value;
    string strscript="<javascript>function getsvalue(){return "+svalue+";}</javascript>"
    Page.RegisterStartupScript("setvalue",strscript);
      

  4.   

    var p1 = document.all.list_ID.value;list_ID是DropDownList的ID
      

  5.   

    string s = "";
    foreach(ListItem li in DropDownList1.Items)
    {
      s += li.Text;
    }js中直接调用这个服务器变量
    <%=s%>
      

  6.   

    再问您一下,如果我要取web控件textBox中的值给javascript的变量呢!还有就怎么把javascript中的值给textBox文本!
      

  7.   

    function  al(val){
    var i=val;
    }

    string val=DropDownList.SelectedItem.Value;
    string script="<javascript>al(" + val + ")</javascript>"
    Page.RegisterStartupScript("setvalue",script);
      

  8.   

    dropdownlist:是服务器控件
    javascript的变量在前台,如何交互啊!!除非在页面事件触发后(页面提交),将其值给到一个前台隐藏的html控件 ,然后javascript的变量=这个html控件的值
      

  9.   

    javascript
    -------------------------------------------------------------------------
    for(i=1;i<document.all("dropdownlist").length;i++)
    {
    if(document.all("dropdownlist").options[i].value == document.all("dropdownlist").value)
    document.all("tt").value = document.all("ddl").options[i].text;
    }tt为客户端控件
      

  10.   

    要是取值就改成这个
    document.all("tt").value = document.all("ddl").options[i].value;
      

  11.   

    要是取值就改成这个
    document.all("tt").value = document.all("ddl").options[i].value;