`

js传入参数是中文的时候出现 “******”未定义错误

obj 
阅读更多

后台代码生成:

 

  sb.append("<a href="****" onclick='getType(' "+pl.getName()+" 
                     ',this)' />");

   out.write(sb.toString());

   out.flush();   
 

页面代码

 

function getType(obj,obj1){
      alert(obj);
     ......................
}

 obj为中文字符串,运行时候会出现

     first:     obj = '钢管'

     result:    '钢管'未定义

 

answer:

      将后台代码中

 

onclick=getType(\""+pl.getName()+\"")................

       加上双引号就可以了......................................

?

why:

    _______________________________

   ________________________________

    ________________________________

   _________________________________

分享到:
评论
1 楼 wuyizhong 2011-02-26  
终于找到答案了……原来没有转义……直接把名称传成参数了……

相关推荐

Global site tag (gtag.js) - Google Analytics