如何使用Javascript在下拉列表或列表框中添加项目? [英] How to Add items in Drop Down List or List Box using Javascript?

查看:93
本文介绍了如何使用Javascript在下拉列表或列表框中添加项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Javascript在下拉列表中添加项目?

How to Add items in Drop Down List using Javascript?

推荐答案

尝试..

try ..
<script type="text/javascript">
    function AddItem(Text,Value)
    {
        // Create an Option object
 
       
        var opt = document.createElement("option");
        
        // Add an Option object to Drop Down/List Box
        document.getElementById("DropDownList").options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;
               
    }
<script />


如果要将dropdown与数据库绑定,则必须使用ajaxcall。

请参阅此链接以获取 Bind ASP.NET中使用jQuery AJAX的下拉列表 [ ^ ]
you must use ajaxcall if you want to bind dropdown with database.
please refer this link for Bind Dropdownlist in ASP.NET using jQuery AJAX[^]


这篇关于如何使用Javascript在下拉列表或列表框中添加项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆