如何使用JavaScript设置ASP控件的值 [英] How can I set the value of ASP Controls using JavaScript

查看:76
本文介绍了如何使用JavaScript设置ASP控件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个ASP控件.一个是文本框,另一个是组合框.

I have two ASP Controls. One is Text Box and another is ComboBox.

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <asp:DropDownList ID="ddlCountry" runat="server"></asp:DropDownList>



现在,我想设置TextBox的值,并使用JavaScript获取dropDown列表的选定索引.



Now I like to set the value of TextBox and Get the selected index of dropDown list using JavaScript.

How can I do these in Java Script?

推荐答案

这是JavaScript基础.这是您的操作方法:
设置文本框值-
This is JavaScript basics. Here is how you will do it:
Set textbox value -
document.getElementById("txtName").value = "somevalue";


获取选定的dropDown索引-


Get the selected index of dropDown -

var index = document.getElementById("ddlCountry").selectedIndex



顺便说一句,在jQuery中这样做会减少编写代码的次数.这就是您在jQuery中做相同事情的方式-



BTW doing this in jQuery will reduce writing code more. Here''s how you do the same thing in jQuery -


(" span>).val(" ); var 索引=
("#txtName").val("somevalue"); var index =


(" ).prop(" );
("#ddlCountry").prop("selectedIndex");


这篇关于如何使用JavaScript设置ASP控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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