ASP.NET,JavaScript的:傻恼人的撇号问题 [英] ASP.NET, javascript: silly annoying apostrophe problem

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

问题描述

我想一个确认框添加到我的ImageButton,所以我有以下几点:

  btn.Attributes.Add(onclick事件,返回确认('确定删除该顾问\\这个小区的名单););

但随后.NET HTML-CN codeS整个事情,因此在HTML出来的:

 的onclick =返回确认(安培;#39;确定要删除该顾问和放这个区;#39;上榜&放大器;?#39;);

所以在顾问撇号看起来一样环绕确认参数的撇号,和JavaScript得到所有困惑和确认框不上来。

删除顾问撇号解决了问题,但我有一个更恼人的标点错误,是不可接受的。

我似乎需要对于撇号的javascript逃离,而这将难逃撇号只为JavaScript,不是HTML ..如果是有道理的。

任何想法??


解决方案

  btn.Attributes.Add(onclick事件,回归确认(\\确定,从顾问删除此区\\的目录\\?););

逃生,并使用确认(...)

I wanted to add a confirmation box to my ImageButton, so I have the following:

btn.Attributes.Add("onclick", "return confirm('OK to delete this district from the consultant\'s list?');");

But then .NET html-encodes the whole thing so it comes out in the HTML as:

onclick="return confirm('OK to delete this district from the consultant's list?');" 

so the apostrophe in "consultant's" looks the same as the apostrophes surrounding the confirm parameter, and javascript gets all confused, and the confirm box does not come up.

Deleting the "consultant's" apostrophe solves the problem, but then I have an even more annoying punctuation error which is unacceptable.

What I seem to need is a "javascript" escape for the apostrophe, something that will escape the apostrophe only for javascript, not for HTML .. if that makes sense.

Any ideas??

解决方案

btn.Attributes.Add("onclick", "return confirm(\"OK to delete this district from the consultant\'s list?\");");

Escape " and use confirm("...")

这篇关于ASP.NET,JavaScript的:傻恼人的撇号问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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