DropDownList 增加一个字符?
如果是text控件写脚本就可以了!

解决方案 »

  1.   

    用JAVA写,就写在onclick后面如何写呢?
    document.all.abc.下来怎么写?
    下来的之类的属性在哪可以查的到呢?
      

  2.   

    function test()
    {
       var i;
       for(i=0;i<document.all['abc'].length;i++)
       {
             document.all['abc'].options[i].text = document.all['abc'].options[i].text+'a';
            //document.all['abc'].options[i].value = document.all['abc'].options[i].value+'a';
       }}
    <INPUT  type="button" value="Button" onclick="test();">
      

  3.   

    对于此类的问题,解决的方法很简单,你在页面上放一个与服务器端控件对应的html控件
    <SELECT id="Select1"  name="Select1" runat="server">
                    <OPTION selected value='1' id='select1_1'>aaa</OPTION>
                </SELECT>
    那么你在写脚本的时候 document.Form1.Select1.后面有什么就会自动出来了
      

  4.   

    <script>
    function addItem(strText,strValue)
    {
        var cbo=document.getElementByID("abc");
        cbo.options[cbo.length]=new Option(str);
    }<INPUT  type="button" value="Button" onclick="addItem('新增项的显示值'.'新增项的实际值');">
      

  5.   

    <script>
    function addItem(strText,strValue)
    {
        var cbo=document.getElementByID("abc");
        cbo.options[cbo.length]=new Option(strText,strValue);
    }<INPUT  type="button" value="Button" onclick="addItem('新增项的显示值'.'新增项的实际值');">
      

  6.   

    两位的代码好像都不行,我把代码合一起,你们试试看,我用的是VS2003中的C#开发,在HTML里编辑什么都跳不出来,在Codebehind里的属性JAVA又不支持...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>javatry</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language="JavaScript">
    function test()
    {
       var i;
       for(i=0;i<document.all['abc'].length;i++)
       {
             document.all['abc'].options[i].text = document.all['abc'].options[i].text+'a';
            //document.all['abc'].options[i].value = document.all['abc'].options[i].value+'a';
       }
       
    function addItem(strText,strValue)
    {
        var cbo=document.getElementByID("Dropdownlist1");
        cbo.options[cbo.length]=new Option(strText,strValue);
    }} </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <INPUT onclick="test();" type="button" value="Button">
    <asp:dropdownlist id="abc" runat="server" Width="200px"></asp:dropdownlist>
    <INPUT onclick="addItem('aaa','bbb');" type="button" value="Button">
    <asp:dropdownlist id="Dropdownlist1" runat="server" Width="200px"></asp:dropdownlist>
    </form>
    </body>
    </HTML>
      

  7.   

    我结合了一下两位高手的代码,发现这样写就OK了,有同样问题的朋友可以看一下.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>javatry</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language="JavaScript">
    function addItem(strText,strValue)
    {
        document.all.Dropdownlist1.options[document.all.Dropdownlist1.length] = new Option(strText,strValue);
    }
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    </asp:dropdownlist><INPUT onclick="addItem('aaa','bbb');" type="button" value="Button">
    <asp:dropdownlist id="Dropdownlist1" runat="server" Width="200px"></asp:dropdownlist></form>
    </body>
    </HTML>
      

  8.   

    我还有个问题
    1.<asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
    2.<asp:dropdownlist id="Dropdownlist1" runat="server" Width="200px">
      <asp:ListItem Value="A">A</asp:ListItem>
      <asp:ListItem Value="B">B</asp:ListItem>
      <asp:ListItem Value="C">C</asp:ListItem>
    </asp:dropdownlist>
    当1中CheckBox1不被点击了,要消除2中比如<asp:ListItem Value="B">B</asp:ListItem>应该如何用JAVA写?比如document.all.checkbox1.checked,还有很多属性在哪查的到呢?或者举些例子还有document.all.button1
    还有document.all.DropDownList1
    ...等这个问题解决了一起给分,这个问题我已经单独提问出来了,两位高手回答一下吧,再进一下那个帖子说句话,然后我就可以一起给分了
      

  9.   

    给你的增删的例子
    由于没用Form,直接用了控件名
    在Form中引用,只要在控件名前面加document.all(在IE中)就行
    <select name=cboValue size=6 Multiple>
    </select>
    <input type=button value=del onclick="DelOption();">
    <br>
    text:<input type=text name=txtText><br>
    Value:<input type=text name=txtValue>
    <input type=button value=Add onclick="AddOption(txtText,txtValue);">
    <script>
    <!--
    function AddOption(txtT,txtV)
    {
        var CurIndex=cboValue.length;
        cboValue.options[CurIndex]=new Option(txtT.value,txtV.value);
    }
    function DelOption()
    {
        //单选的删除
        //var CurIndex=cboValue.selectedIndex;
        //cboValue.options[CurIndex]=null;
        //多选的删除
        for(var i=cboValue.length-1;i>=0;i--)
        {
            if(cboValue.options[i].selected)
                cboValue.options[i]=null;
        }
    }
    //-->
    </script>
      

  10.   

    <script language="JavaScript">
    function AddItem(strText,strValue)
    {
        document.all.Dropdownlist1.options[document.all.Dropdownlist1.length] = new Option(strText,strValue);
    }function DelItem(strText)
    {
        for(var i=0;i<document.all.Dropdownlist1.length;i++)
        {
            if(document.all.Dropdownlist1.options[i].text==strText)
            {
                document.all.Dropdownlist1.options[i]=null;
            }
        }
    }
    </script>
    <asp:CheckBox id="CheckBox1" runat="server" onclick="DelItem('B');"></asp:CheckBox>
    <asp:dropdownlist id="Dropdownlist1" runat="server" Width="200px">
    <asp:ListItem Value="A">A</asp:ListItem>
    <asp:ListItem Value="B">B</asp:ListItem>
    <asp:ListItem Value="C">C</asp:ListItem>
    </asp:dropdownlist>    天堂客,我的问题是:让CheckBox打勾的时候添加,勾点掉的时候去掉一个值,我现在只知道一个onclick方法,也不想增加一个变量来控制.我想问一下是不是本来就有这个方法的?怎么写?
        那个20分的贴已经结了,我还有个100分的贴和这个60(20分给零零五)的贴,回答了分都给你.
      

  11.   

    <asp:CheckBox id="CheckBox1" runat="server" onclick="setItem(this,'显示值'.'实际值');"></asp:CheckBox>
    <script language="JavaScript">
    function setItem(Chk,strText,strValue)
    {
        if(chk.checked)
        {
             document.all.Dropdownlist1.options[document.all.Dropdownlist1.length] = new Option(strText,strValue);
        else
        {
            for(var i=0;i<document.all.Dropdownlist1.length;i++)
            {
                if(document.all.Dropdownlist1.options[i].text==strText)
                     document.all.Dropdownlist1.options[i]=null;
            }
        }
    }
    </script>