javascript操作select和AjaxPro返回数组点滴
一:javascript操作select
var selectobj = document.getElementByID('select');
var selectedindex = selectobj.selectedIndex;
//设置选中
selectobj.option[i].selected = true;
//获取选中的option的value和text
var val = selectobj.options[selectedindex].value;
var text = selectobj.options[selectedindex].text;
//遍历option
for(var i=0;i<selectobj.options.length;i++)
{
selectobj.options[i]........
}
var selectedindex = selectobj.selectedIndex;
//设置选中
selectobj.option[i].selected = true;
//获取选中的option的value和text
var val = selectobj.options[selectedindex].value;
var text = selectobj.options[selectedindex].text;
//遍历option
for(var i=0;i<selectobj.options.length;i++)
{
selectobj.options[i]........
}
二:AjaxPro返回自定义对象列表
1 /*
2 *自定义对象一定要标明可以序列化
3 *使用Serializable关键字声明
4 */
2 *自定义对象一定要标明可以序列化
3 *使用Serializable关键字声明
4 */
[Serializable]
5 class SerClass{
6 private string id;
7 private string name;
8 public string Id{
9 get{ return id; }
10 set{ id = Value;}
11 }
12 public string Name{
13 get{ return name;}
14 set{ name = Value;}
15 }
16 }
5 class SerClass{
6 private string id;
7 private string name;
8 public string Id{
9 get{ return id; }
10 set{ id = Value;}
11 }
12 public string Name{
13 get{ return name;}
14 set{ name = Value;}
15 }
16 }
后台方法:
1 //普通操作仅仅声明[AjaxPro.AjaxMethod]即可
2 //若要操作Seesion,则声明成[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
3
4 [AjaxPro.AjaxMethod]
5 public List<SerClass> QueryList(){
6 List<SerClass> objlist = new List<SerClass>();
7 SerClass obj = new SerClass();
8 obj.ID = "";
9 obj.Name = "";
10 objlist.Add(obj);
11 .........
12 return objlist;
13 }
2 //若要操作Seesion,则声明成[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
3
4 [AjaxPro.AjaxMethod]
5 public List<SerClass> QueryList(){
6 List<SerClass> objlist = new List<SerClass>();
7 SerClass obj = new SerClass();
8 obj.ID = "";
9 obj.Name = "";
10 objlist.Add(obj);
11 .........
12 return objlist;
13 }
客户端调用:
1 var result = 类名.QueryList();
2 if(result.error != null ){
3 alert(result.error.Message);
4 return false;
5 }
6 for(var i=0; i< result.length;i++){
7 result[i].ID;
8 result[i].Name;
9 }
2 if(result.error != null ){
3 alert(result.error.Message);
4 return false;
5 }
6 for(var i=0; i< result.length;i++){
7 result[i].ID;
8 result[i].Name;
9 }