日期:2014-05-18  浏览次数:21045 次

asp.net 向javascript传递参数的问题
这是javascript函数 
function changeASort(DDLA,DDLC) { 
  var id = DDLA; 
  var id2 = DDLC; 
  alert(id); 
  alert(id2); 


这是asp.net的部分函数 
DropDownList DDListSort = new DropDownList(); 
DDListSort.ID = "DDListSort" + ControlName; 
string DDListASortID = "DDListASort" + ControlName; 
DDListSort.Attributes.Add("onchange", "changeASort(" + DDListSort.ID + "," + DDListASortID + ");"); 

问题: 
触发changeASort函数,可是DDLA的值不是等于DDListSort.ID ,而是等于object

------解决方案--------------------
加个单引号
DDListSort.Attributes.Add("onchange", "changeASort('" + DDListSort.ID + "'," + DDListASortID + ");");
------解决方案--------------------
加个单引号 
DDListSort.Attributes.Add("onchange", "changeASort( '" + DDListSort.ID + " '," + DDListASortID + ");");

正解!
------解决方案--------------------
DDListSort.Attributes.Add("onchange", "changeASort( '" + DDListSort.ID + " '," + DDListASortID + ");");
传值应该加上单引号。JS中值不为空时就表示为一个对象object,你可以现typeof测试一下。。。