从javascript字符串中删除字符/

时间:2013-05-22 21:16:50

标签: javascript asp.net-mvc

概述: 我将一个字符串传递给我的javascript函数,这里是代码:

HTML:

<span onclick='fSaveComment(/@item.model.szUserName/)'></span>

使用Javascript:

function fSaveComment(szUserName) {  

   // If I assign the following line, it strips the first and last characters,
   // if I use szUserName from the function param list, it does not work!!!
   // 
   //szUserName = '/aabbcc/'; 

   myString = szUserName.substr(1, szUserName.length-2);                             
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要正确引用传递给fSaveComment函数的用户名

<span onclick='fSaveComment("@item.model.szUserName")'></span>