JavaScript的单引号问题 [英] javascript single quote issue

查看:149
本文介绍了JavaScript的单引号问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建asp.net C#的Web应用程序。
我上的GridView的每一行的第一列具有一个LinkBut​​ton(lnkDelete)。
另外,我动态地添加属性里面的GridView的的RowDataBound事件链接按钮。
就像如下:

I creating asp.net c# web application. I have a linkButton (lnkDelete) on first column of each row of gridview. Also i am adding an attribute dynamically to that link button inside "RowDataBound" event of GridView. Like as follows :

  lnkDelete.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to   delete this Product :" +
                    DataBinder.Eval(e.Row.DataItem, "ProductName") + "')");

现在我所要做的,当用户点击该链接按钮JavaScript的confirm弹出开拓,问:你确定要删除这个产品的说法。
每一件事情做工精细。但问题occures,在产品的名称带有SNGLE报价。
像:Product'One。
语法错误进来ErrorConsole(JavaScript的)当我点击lnkDelete和错误是:(非法字符)
我知道这个问题是单引号。

Now What i am trying to do is when user click that link button a javascript confirm popup open up ,asking "Are you sure you want to delete this product". Every thing work fine . But Problem occures when the name of the products comes with sngle quote. Like : Product'One. Syntax Error comes in ErrorConsole (javascript) when i click lnkDelete and error is : ( illegal character ) I know the problem is with single quote.

请给我建议。
我希望我是清楚的。

Please suggest me what change required in my above code. I hope i am clear.

推荐答案

如何在单引号加入 \\

DataBinder.Eval(e.Row.DataItem, "ProductName").ToString.Replace("'", "\\'")

这篇关于JavaScript的单引号问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆