![](/img/trans.png)
[英]JavaScript remove a character from a string and remove the previous character
[英]remove the character / from a javascript string
概述:我正在將字符串傳遞給我的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);
}
我究竟做錯了什么?
您需要正確引用傳遞給fSaveComment函數的用戶名
<span onclick='fSaveComment("@item.model.szUserName")'></span>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.