如何在jquery中更改ASP:dropdownlist selectionindex [英] How to change ASP:dropdownlist selectionindex in jquery

查看:63
本文介绍了如何在jquery中更改ASP:dropdownlist selectionindex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在jquery点击按钮时更改selectionIndex

我的代码是



I want to change selectionIndex on button click in jquery
My Code is

<asp:DropDownList runat="server" ID="d">

</asp:DropDownList>





我尝试过:



$(文件).ready(function(){

尝试{



$('#<%= d.ClientID%>')。on('change',function(){

T ry {

var ban = $('#<%= d.ClientID%>')。val();

alert(ban);



}

catch(e){



}

});

a();

}

catch(e){

alert(e) ;

}



});





函数a(){

尝试

{$([id * = d])。empty();

var _select = $(< select>);

_select.append($(< option value ='0'> Select One< / option>));

_select.append($(< option value ='1'> One< / option>));

_select.append($(< option value ='2'> Two< / option>));

$([ id * = d])。append(_select.html());

$('#<%= d.ClientID%>')。val('1');

$('#<%= d.ClientID%>')。change();



}

catch(e)

{

alert(e);

}

}



无效。







如果我添加静态选项



< option value ='0'>选择一个< /选项>

<选项值='1'>一个< /选项>

< option value ='2'>两个< / option>

并修改一个()函数

函数a(){

尝试

{

$('#<%= d.ClientID%> ;')。val('1');

$('#<%= d.ClientID%>')。change();



} < br $> b $ b catch(e)

{

alert(e);

}

}

现在它正在工作



What I have tried:

$(document).ready(function () {
try {

$('#<%=d.ClientID %>').on('change', function () {
try {
var ban = $('#<%=d.ClientID %>').val();
alert(ban);

}
catch (e) {

}
});
a();
}
catch (e) {
alert(e);
}

});


function a() {
try
{ $("[id*=d]").empty();
var _select = $("<select>");
_select.append($("<option value='0'>Select One</option>"));
_select.append($("<option value='1'>One</option>"));
_select.append($("<option value='2'>Two</option>"));
$("[id*=d]").append(_select.html());
$('#<%=d.ClientID %>').val('1');
$('#<%=d.ClientID %>').change();

}
catch(e)
{
alert(e);
}
}

It is not working.



If I add statically option to

<option value='0'>Select One</option>
<option value='1'>One</option>
<option value='2'>Two</option>
and modify a() function
function a() {
try
{
$('#<%=d.ClientID %>').val('1');
$('#<%=d.ClientID %>').change();

}
catch(e)
{
alert(e);
}
}
Now it is working

推荐答案

(document).ready(function(){

try {


(document).ready(function () {
try {


('#<%= d.ClientID%>')。on('change',function(){

尝试{

var ban =
('#<%=d.ClientID %>').on('change', function () {
try {
var ban =


('#<%= d.ClientID%>')。val() ;

提醒(禁令);



}

catch(e){



}

});

a();

}

catch(e){

alert(e);

}



});





函数a() {

尝试

{
('#<%=d.ClientID %>').val();
alert(ban);

}
catch (e) {

}
});
a();
}
catch (e) {
alert(e);
}

});


function a() {
try
{


这篇关于如何在jquery中更改ASP:dropdownlist selectionindex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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