如何获取下拉列表中的下拉值 [英] How to get dropdown value on dropdown bind

查看:86
本文介绍了如何获取下拉列表中的下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ajax绑定下拉列表。 iam在使用所选事件的下拉绑定中设置默认值。如果下拉列表完成绑定。我想在默认情况下获得选定的值。和iam更改另一个下拉列表,在页面加载时使用此默认值







感谢问候



我尝试过:



函数addSelect(divname,columname,defaultvalue ,dropid,tablename,pd,userid,chartid,filte){

var newDiv = document.createElement(pd);

var change =onchange ='dropchange(this )'';

var html ='< select'+ change +'title ='+ defaultvalue +'id ='+ dropid +'name ='+ columname +' >'

var obj = {};

obj.coluname = columname;

obj.tablename = tablename;

obj.userid = userid;

obj.chartid = chartid;

obj.filte = filte;

$ .ajax( {

url:webmethod.aspx / dropdownbine,

数据:JSON.stringify(obj),

dataType:json,

类型:POST,

contentType:application / json; charset = utf-8,

成功:功能(r){



var result = rd;

var sel =All;

var selected =true;

html + =< option Value ='+ sel +'title =' + defaultvalue +'>+ sel +< / option>;

for(i = 0; i< result.length; i ++)

{

if(defaultvalue == result [i])

{

html + =< option selected ='+ selected +'value ='+ result [i] +'>+ result [i] +< / option>;

}

else {

html + =< option value ='+ result [i] +'>+ result [i] +< / option>;

}

}

html + ='< / select>';

newDiv.innerHTML = html;

document.getElementById(divname).appendChild(newDiv);



},

错误:函数(XMLHttpRequest,textStatus,errorThrown){

alert('得到错误下拉列表绑定');

}

} );



}











var a = $ .trim($([id * = chart0Filter2drop0])。val());

解决方案

.ajax({

url:webmethod.aspx / dropdownbine,

数据:JSON.stringify(obj),

dataType:json,

类型:POST,

contentType:application / json; charset = utf-8,

成功:功能(r){



var result = rd;

var sel =All;

var selected =true;

html + =< option Value ='+ sel +'title =' + defaultvalue +'>+ sel +< / option>;

for(i = 0; i< result.length; i ++)

{

if(defaultvalue == result [i])

{

html + =< option selected ='+ selected +'value ='+ result [i] +'>+ result [i] +< / option>;

}

else {

html + =< option value ='+ result [i] +'>+ result [i] +< / option>;

}

}

html + ='< / select>';

newDiv.innerHTML = html;

document.getElementById(divname).appendChild(newDiv);



},

错误:函数(XMLHttpRequest,textStatus,errorThrown){

alert('得到错误下拉列表绑定');

}

} );



}











var a =


.trim(


([id * = chart0Filter2drop0])VAL());

iam binding the dropdown using ajax. iam set default value on dropdown bind useing selected event. if dropdown complete the bind. i want to get selected value on default. and iam change another dropdown to use of this default value on page load



thanks Regards

What I have tried:

function addSelect(divname, columname, defaultvalue,dropid, tablename, pd, userid, chartid, filte) {
var newDiv = document.createElement(pd);
var change = " onchange='dropchange(this)' ";
var html = '<select ' + change + ' title="' + defaultvalue + '" id="' + dropid + '" name = "' + columname + '" >'
var obj = {};
obj.coluname = columname;
obj.tablename = tablename;
obj.userid = userid;
obj.chartid = chartid;
obj.filte = filte;
$.ajax({
url: "webmethod.aspx/dropdownbine",
data: JSON.stringify(obj),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(r) {

var result = r.d;
var sel = "All";
var selected="true";
html += "<option Value='" + sel + "' title ='" + defaultvalue + "'>" + sel + "</option>";
for (i = 0; i < result.length; i++)
{
if(defaultvalue==result[i])
{
html += "<option selected='" + selected + "' value='" + result[i] + "'>" + result[i] + "</option>";
}
else {
html += "<option value='" + result[i] + "'>" + result[i] + "</option>";
}
}
html += '</select>';
newDiv.innerHTML = html;
document.getElementById(divname).appendChild(newDiv);

},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Got an Error Dropdownlist bind ');
}
});

}





var a =$.trim($("[id*=chart0Filter2drop0]").val());

解决方案

.ajax({
url: "webmethod.aspx/dropdownbine",
data: JSON.stringify(obj),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(r) {

var result = r.d;
var sel = "All";
var selected="true";
html += "<option Value='" + sel + "' title ='" + defaultvalue + "'>" + sel + "</option>";
for (i = 0; i < result.length; i++)
{
if(defaultvalue==result[i])
{
html += "<option selected='" + selected + "' value='" + result[i] + "'>" + result[i] + "</option>";
}
else {
html += "<option value='" + result[i] + "'>" + result[i] + "</option>";
}
}
html += '</select>';
newDiv.innerHTML = html;
document.getElementById(divname).appendChild(newDiv);

},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Got an Error Dropdownlist bind ');
}
});

}





var a =


.trim(


("[id*=chart0Filter2drop0]").val());


这篇关于如何获取下拉列表中的下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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