热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在标题属性中转义双引号-Howtoescapedoublequotesintitleattribute

Iamtryingtouseastringthatcontainsdoublequotesinthetitleattributeofananchor.Sofar

I am trying to use a string that contains double quotes in the title attribute of an anchor. So far I tried these:

我正在尝试使用一个字符串,该字符串在锚的title属性中包含双引号。到目前为止,我尝试了以下方法:

Some text

and

Some text

Please note that using single quotes is not an option.

请注意,使用单引号不是一个选项。

8 个解决方案

#1


227  

This variant -

这变种-

Some text

Is correct and it works as expected - you see normal quotes in rendered page.

是正确的,并且它可以按预期工作—您可以在呈现的页面中看到正常的引号。

#2


19  

EDIT: Link appears to be dead, so here's a snippet of the escape characters taken from a cached page on archive.org:

编辑:链接似乎是死的,所以这里有一个转义字符的片段,从archive.org上缓存的页面中获取:

&#060   |   less than sign  <
&#064   |   at sign @       
&#093   |   right bracket   ]       
&#123   |   left curly brace    {       
&#125   |   right curly brace   }       
&#133   |   ellipsis    …       
&#135   |   double dagger   ‡       
&#146   |   right single quote  ’       
&#148   |   right double quote  ”       
&#150   |   short dash  –       
&#153   |   trademark   ™       
&#162   |   cent sign   ¢       
&#165   |   yen sign    ¥       
&#169   |   copyright sign  ©       
&#172   |   logical not sign    ¬       
&#176   |   degree sign °       
&#178   |   superscript 2   ²       
&#185   |   superscript 1   ¹       
&#188   |   fraction 1/4    ¼       
&#190   |   fraction 3/4    ¾       
&#247   |   division sign   ÷       
&#8221  |   right double quote  ”       
&#062   |   greater than sign   >   
&#091   |   left bracket    [   
&#096   |   back apostrophe `   
&#124   |   vertical bar    |   
&#126   |   tilde   ~   
&#134   |   dagger  †   
&#145   |   left single quote   ‘       
&#147   |   left double quote   “   
&#149   |   bullet  •   
&#151   |   longer dash —   
&#161   |   inverted excallamation point    ¡   
&#163   |   pound sign  £   
&#166   |   broken vertical bar ¦   
&#171   |   double left than sign   «   
&#174   |   registered trademark sign   ®   
&#177   |   plus or minus sign  ±   
&#179   |   superscript 3   ³   
&#187   |   double greather than sign   »   
&#189   |   fraction 1/2    ½   
&#191   |   inverted question mark  ¿   
&#8220  |   left double quote   “   
&#8212  |   dash    —   

/EDIT

/编辑

Give this a shot

给这一枪

HTML Escape character list.

HTML转义字符列表。

It's a great reference for all of these characters.

这对所有这些角色都是很好的参考。

#3


6  

Does " instead of " work?

& # 34;而不是“;工作吗?

#4


3  

Using " is the way to do it, I tried you second code snippet and it works on both Firefox and IE.

使用“;就是这么做的,我试过你第二段代码,它在Firefox和IE上都能运行。

#5


2  

It may work with any character from the HTML Escape character list, but I had the same problem with a Java project. I used StringEscapeUtils.escapeHTML("Testing \"

") and the title was

">Testing.

它可能与HTML转义字符列表中的任何字符一起工作,但是我在Java项目中遇到了同样的问题。我使用了StringEscapeUtils.escapeHTML("测试\"

"),标题为

It only worked for me when I changed the StringEscapeUtils to StringEscapeUtils.escapeJavascript("Testing \"

") and it worked in every browser.

它只在我将StringEscapeUtils改成stringescapeutills . escapeJavascript(“Testing \”

”)时对我有效,并且在每个浏览器中都可以使用。

#6


1  

There is at least one situation where using single quotes will not work and that is if you are creating the markup "on the fly" from Javascript. You use single quotes to contain the string and then any property in the markup can have double quotes for its value.

至少有一种情况是单引号不起作用,那就是如果您正在从Javascript创建标记“on the fly”。您可以使用单引号来包含字符串,然后标记中的任何属性都可以有双引号。

#7


0  

Perhaps you can use Javascript to solve your cross-browser problem. It uses a different escape mechanism, one with which you're obviously already familiar:

也许您可以使用Javascript来解决跨浏览器的问题。它使用一种不同的逃避机制,显然你已经很熟悉了:

(reference-to-the-tag).title = "Some \"text\"";

It doesn't strictly separate the functions of HTML, JS and CSS the way folks want you to nowadays, but whom do you need to make happy? Your users or techies you don't know?

它并没有严格地将HTML、JS和CSS的功能与现在的人们想要的方式分开,但是你需要让谁开心呢?你不认识的用户或技术人员?

#8


-1  

You can use this PHP code to list special characters...

您可以使用此PHP代码来列出特殊字符…

&#$i;&#".$i.";"; ?>

推荐阅读
  • 简单动态字符串redis里面很多地方都用到了字符串,我们知道redis是一个键值对存储的非关系型数据库,那么所有的key都是用字符串存储的,还有字符串类型,这些都是用字符串存储的 ... [详细]
  • iOS之富文本
    之前做项目时遇到一个问题:使用UITextView显示一段电影的简介,由于字数比较多,所以字体设置的很小,行间距和段间距也很小,一大段文字挤在一起看起来很别扭,想要把行间距调大,结 ... [详细]
  • 如何设计一个秒杀系统(各方面都写的很到位)
    1.Overview1.1并发读写秒杀要解决的主要问题是:并发读与并发写。并发读的优化理念是尽量减少用户到服务端来读数据,或者让他 ... [详细]
  • 九宫格计算. ... [详细]
  • 本文分析和介绍了GLo ... [详细]
  • 通过CreateDirectory命令创建相应的Directory之后,可以将目录的访问权限授予其他用户,这样其他用户就能通过外部表访问很多主机上的文件,而不需要登录到数据库服务器 ... [详细]
  • MyBatis模糊查询和多条件查询一、ISmbmsUserDao层根据姓名模糊查询publicListgetUser();多条件查询publicList ... [详细]
  • 最近自己做一个工具最后涉及到一个存储成bmp位图的形式,由于这部分并不是整个project的重点我就从网上找了例子改了改,但是目前的问题是有很多时候都是存储的bmp全黑,我也并不知道是怎么回事。 ... [详细]
  • 最近想用js做一个简单的计算器,不过网上的例子好像大部分都是直接从左到右挨个计算,就好像1+2*5,就会先计算1+2,再计算3*5,并没有实现运算符的优先级,这里找到了一种方法实现,来总结一下。不过这 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了将JSON数组反序列化为强类型的.NET对象相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 下面是一个用openssl实现获取https网页内容的demo,整个流程比较简单,主要封装的API如下staticinthttps_init(http ... [详细]
  • Spark 贝叶斯分类算法
    一、贝叶斯定理数学基础我们都知道条件概率的数学公式形式为即B发生的条件下A发生的概率等于A和B同时发生的概率除以B发生的概率。根据此公式变换,得到贝叶斯公式:即贝叶斯定律是关于随机 ... [详细]
  • AsyncDisplayKit2.0教程(下)
    AsyncDisplayKit2.0Tutorial:AutomaticLayout原文:AsyncDisplayKit2.0Tutorial:Automatic ... [详细]
  • 本节书摘来自华章计算机《Web前端开发最佳实践》一书中的第2章,第2.2节,作者:党 建更多章节内容可以访问云栖社区“华章计算机”公众号查看。2.2 前端代码重构代码 ... [详细]
  • SpringBoot与缓存使用及原理(上),Go语言社区,Golang程序员人脉社 ... [详细]
author-avatar
何俊雨_127
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有