客户端下拉列表更改选择 [英] Dropdownlist change selection on client

查看:103
本文介绍了客户端下拉列表更改选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨组,


我正在尝试改变ASP下拉列表的选择,就像

Orange一样。在此处选择:

http: //www.w3schools.com/js/tryit.as...ption_selected


以下在IE上运行正常:


document.getElementById(''dropdown'')。options.select ed = 0 //

选择第一个选项


但是,我需要这个也可以在其他浏览器上工作。


我首先添加了id。属性为ASP:ListItem,以便

通过他们的ID访问它们(就像上面的W3C例子中一样),但它确实没有在生成的HTML页面中呈现



我怎样才能以标准的方式在浏览器中实现这个目标?


谢谢。

解决方案

5月26日上午7:04,harold.gime ... @ gmail.com写道:


嗨组,


我正在尝试更改ASP下拉列表的选择,就像

Orange一样。在此处选择:

http: //www.w3schools.com/js/tryit.as...ption_selected


以下在IE上运行正常:


document.getElementById(''dropdown'')。options.select ed = 0 //

选择第一个选项


但是,我需要这个也可以在其他浏览器上工作。


我首先添加了id。属性为ASP:ListItem,以便

通过他们的ID访问它们(就像上面的W3C例子中一样),但它确实没有在生成的HTML页面中呈现



我怎样才能以标准的方式在浏览器中实现这个目标?


谢谢。






请查看此链接...在此博客文章中我删除了几行

可能对你有帮助
http://munnacs.blogspot.com/2007/05/...ml-select.html


谢谢

Masudur


5月26日上午12:41,Masudur< munn ... @ gmail.comwrote:


5月26日上午7:04,harold.gime ... @ gmail.com写道:


嗨组,


我正在尝试更改ASP下拉列表的选择,就像

" Orange"在这里选择:

http://www.w3schools.com/js/tryit.as...ption_selected


以下工作正常IE:


document.getElementById(''dropdown'')。options.select ed = 0 //

选择第一个选项


但是,我需要这个也适用于其他浏览器。


我首先添加了id"属性为ASP:ListItem,以便

通过他们的ID访问它们(就像上面的W3C例子中一样),但它确实没有在生成的HTML页面中呈现


我怎样才能以标准方式在浏览器中实现这一目标?


谢谢。






请查看此链接...在此博客文章中我删除了几行

这可能对你有所帮助:http://munnacs.blogspot.com/2007/05/select-items-of-html-select.html


谢谢

Masudur



感谢您的回复。


我在博客上试过的另一件事并没有真正解决要么:


document.getElementById(''dropdown'')。value =" 1";





document.getElementById(''dropdown'')。options [1] .selected = true;

这两个适用于IE7但不适用于Firefox。


我想底线是:有没有办法将id分配给列表

元素,以便我使用getElementById(''option1'')来访问它们Firefox上的
?也许后面的代码有一种方法可以添加这个

属性...


我使用的是.NET Framework 1.1 ...


再次感谢。


5月26日下午6:20,harold.gime ... @ gmail.com写道:


document.getElementById(''dropdown'')。options.select ed = 0 //

选择第一个选项



document.getElementById(''dropdown'')。selectedIndex = 0

应该有帮助。


Hi group,

I am trying to change the selection of an ASP Dropdownlist just like
"Orange" is selected here:

http://www.w3schools.com/js/tryit.as...ption_selected

The following works fine on IE:

document.getElementById(''dropdown'').options.select ed = 0 //
selects the first option

But, I need this to work on other browsers as well.

I started by adding the "id" attribute to the ASP:ListItem in order to
access them by their ID (like in the W3C example above), but it does
not get rendered in the produced HTML page.

How could I achieve this in a crossbrowser, standard way?

Thanks.

解决方案

On May 26, 7:04 am, harold.gime...@gmail.com wrote:

Hi group,

I am trying to change the selection of an ASP Dropdownlist just like
"Orange" is selected here:

http://www.w3schools.com/js/tryit.as...ption_selected

The following works fine on IE:

document.getElementById(''dropdown'').options.select ed = 0 //
selects the first option

But, I need this to work on other browsers as well.

I started by adding the "id" attribute to the ASP:ListItem in order to
access them by their ID (like in the W3C example above), but it does
not get rendered in the produced HTML page.

How could I achieve this in a crossbrowser, standard way?

Thanks.

Hi,

Please check this link ... in this blog post i have dropped few lines
which might help you
http://munnacs.blogspot.com/2007/05/...ml-select.html

Thanks
Masudur


On May 26, 12:41 am, Masudur <munn...@gmail.comwrote:

On May 26, 7:04 am, harold.gime...@gmail.com wrote:

Hi group,

I am trying to change the selection of an ASP Dropdownlist just like
"Orange" is selected here:

http://www.w3schools.com/js/tryit.as...ption_selected

The following works fine on IE:

document.getElementById(''dropdown'').options.select ed = 0 //
selects the first option

But, I need this to work on other browsers as well.

I started by adding the "id" attribute to the ASP:ListItem in order to
access them by their ID (like in the W3C example above), but it does
not get rendered in the produced HTML page.

How could I achieve this in a crossbrowser, standard way?

Thanks.


Hi,

Please check this link ... in this blog post i have dropped few lines
which might help youhttp://munnacs.blogspot.com/2007/05/select-items-of-html-select.html

Thanks
Masudur

Thanks for your reply.

The other thing I tried from your blog did not really work out either:

document.getElementById(''dropdown'').value = "1";

or

document.getElementById(''dropdown'').options[1].selected = true;
These two work on IE7 but not Firefox.

I guess the bottom line is: is there a way to assign id s to the list
elements in order for me to access them with getElementById(''option1'')
on Firefox? Maybe there is a way on the code behind to add this
attribute...

I am using .NET Framework 1.1...

Thanks again.


On May 26, 6:20 pm, harold.gime...@gmail.com wrote:

document.getElementById(''dropdown'').options.select ed = 0 //
selects the first option

document.getElementById(''dropdown'').selectedIndex = 0

should help.


这篇关于客户端下拉列表更改选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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