如何在Dropdownlist中更改文本? [英] How do change text in Dropdownlist ?

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

问题描述

大家好。我使用Dropdownlist。我尝试在Dropdownlist中更改文本,但我不能。似乎它丢失了一些数据。



ie:在Dropdownlist中我有三个数据:AREA1,AREA2,AREA3,它从ajax加载。

< select id =   cbo_area> < /  选择 >  
function cb_area(){
$ .ajax(
{
type: POST
url: 。 ./BUS/WebService.asmx/LIST_AREA // //获取列表所有区域
contentType: application / json; charset = utf-8
dataType:< span class =code-string> json
成功: function (data){
$( #cbo_area)。html(' ');
$ .each($。parseJSON(data.d), function (idx,obj){
$( #cbo_area)。append(
' < span class =code-string>< option value =' + obj.AREA_ID + ' >' + obj.AREA_NAME + ' < / option>');
});
},
错误: function (数据){
alert( HTML Error Load Combo);
}
});
}



好​​的,在我的表格中,我点击行然后点击编辑按钮,它会显示从行到下拉列表的数据。它工作,但它只显示一个数据,在这种情况下AREA2(在Dropdown中丢失AREA1和AREA3),我尝试点击另一行,我得到了正确的,在这种情况下AREA3(在Dropdown中丢失了AREA1和AREA2),等...

 $(' #bt_edit' )。点击(功能(e){
var DTO = {
' area_id':area_id_temp
};
$ .ajax(
{
类型: POST
url:< span class =code-string> ../ BUS / WebService.asmx / AREA_NAME // / get name area follow id
data: JSON .stringify(DTO),
contentType: 应用/ JSON; charset = utf-8
dataType: json
成功: function (数据){
$( #cbo_area)。html(' ');
// cb_area(); //无效,它会循环数据两次
// /它只会在Dropdownlist中显示一个数据
$ .each($。parseJSON (data.d), function (idx,obj){
$( #cbo_area)。append(
' < option value =' + obj.AREA_ID + ' >' + obj.AREA_NAME + ' < /选项>');
});
// cb_area(); //没有用,它会加载错误的数据
},
错误: function (数据){
alert ( HTML错误加载编辑);
}
});
});





我想点击表格中的一行,Dropdownlist将更改行中的文本并与剩余字段同时数据。即:当我点击一行有AREA1时,Dropdownlist文本将改变AREA1和更多AREA2,AREA3。请给我一些建议。

如上所述,我可以通过cb_area函数将数据加载到下拉列表中。我想点击表格中的行,数据下拉列表会更改,其他字段也会更改。



示例:Dropdownlist总共有三个文本数据:AREA1,AREA2, AREA3。



我的桌子



<前lang =HTML> 1 ABC 123 AREA1

2 EFG 456 AREA2

3 IJK 789 AREA1

4 EFG 011 AREA3





我将点击第2行,然后点击编辑按钮。在这里,dropdownlist中的文本需要更改AREA2,AREA1,AREA3。 ,如果我单击第4行,然后单击编辑按钮,下拉列表中的文本需要更改AREA3,AREA1,AREA2,...等



这意味着文本下拉列表将根据表格中的行数据进行更改,此外还必须包含其他数据

最好的问候。

谢谢。

解决方案

.ajax(
{
type: POST
url: ../ BUS / WebService.asmx / LIST_AREA // //获取所有区域的列表
contentType: application / json; charset = utf-8
dataType: json
成功: function (data){


#cbo_area)。html(' ');

。每个(

Hello guys. I have use Dropdownlist . I try change text in Dropdownlist , but i can not. Seem it losts some data .

i.e : in Dropdownlist i have three data: AREA1,AREA2,AREA3, it load from ajax .

<select id="cbo_area"></select>
   function cb_area() {
                $.ajax(
                {
                    type: "POST",
                    url: "../BUS/WebService.asmx/LIST_AREA", //// get list all area
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $("#cbo_area").html('');
                        $.each($.parseJSON(data.d), function (idx, obj) {
                            $("#cbo_area").append(
                                '<option value="' + obj.AREA_ID + '">' + obj.AREA_NAME + '</option>');
                        });
                    },
                    error: function (data) {
                        alert("HTML Error Load Combo");
                    }
                });
            }


Ok, in my table , i click at row then click edit button, it will show data from row to Dropdownlist. it work but it only show one data , in this case "AREA2" (lost AREA1 and AREA3 in Dropdown) , i try click another row , i get that right , in this case "AREA3" (lost AREA1 nad AREA2 in Dropdown), etc...

$('#bt_edit').click(function (e) {
                    var DTO = {
                        'area_id': area_id_temp
                    };
                    $.ajax(
                    {
                        type: "POST",
                        url: "../BUS/WebService.asmx/AREA_NAME",  /// get name area follow id
                        data: JSON.stringify(DTO),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            $("#cbo_area").html('');
                           //cb_area(); // no work , it will loop data two times
                           /// it only will one data in Dropdownlist
                            $.each($.parseJSON(data.d), function (idx, obj) {
                                $("#cbo_area").append(
                                    '<option value="' + obj.AREA_ID + '">' + obj.AREA_NAME + '</option>');
                            });
                           //cb_area();  // no work, it will load wrong data
                        },
                        error: function (data) {
                            alert("HTML Error Load Edit");
                        }
                    });
});



I want to click a row in table , Dropdownlist will change text from row and concurrent with fields remaining data. i.e : when i click a row have "AREA1" , Dropdownlist text will change "AREA1" and more "AREA2" , "AREA3". Please give me some advice about this .
As I said above, I can load data into dropdownlist via cb_area function. I want to click on the row in the tables, data dropdownlist will change and additional the remaining fields.

Example: Dropdownlist alway have three text data : AREA1, AREA2, AREA3.

My table

1   ABC       123      AREA1

2   EFG        456     AREA2

3   IJK          789     AREA1

4   EFG         011    AREA3



I will click a row 2 , then click edit button . In here text in dropdownlist need to change AREA2, AREA1,AREA3 . , If i click a row 4, then click edit button, text in dropdownlist need to change AREA3,AREA1,AREA2 ,...etc

This means that text in dropdownlist will change according to the data of the line on the table, besides it must also other data
Best Regards.
Thank you.

解决方案

.ajax( { type: "POST", url: "../BUS/WebService.asmx/LIST_AREA", //// get list all area contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) {


("#cbo_area").html('');


.each(


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

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