Html 如何在html输入值中使用引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1593800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:05:21  来源:igfitidea点击:

how to have quotation marks in html input values

htmlescaping

提问by tobi

i have following problem - from the server side i get a string like 'hoschi"brother' i want to put this string into a <input value"MYSTRING" />. this results in something like <input value"hoschi" brother" />which obviously does not work.

我有以下问题 - 从服务器端我得到一个像 'hoschi"brother' 这样的字符串,我想把这个字符串放到 a 中<input value"MYSTRING" />。这会导致类似的东西 <input value"hoschi" brother" />显然不起作用。

any workarounds for this? does escaping the "character with &quot;work within the value tag?

任何解决方法?"使用&quot;值标签内的工作来转义字符吗?

thanks for your help, tobi

谢谢你的帮助,托比

回答by Dominic Rodger

Yes, using &quot;works:

是的,使用&quot;作品:

<input type="text" name="last_name" value="&quot;My quote!&quot;" />

回答by Quentin

does escaping the " character with &quot; work within the value tag?

在值标签中使用“转义”字符是否有效?

Yes. (This isn't a workaround though, it is how HTML is designed to work).

是的。(不过,这不是一种解决方法,它是 HTML 的设计方式)。

Alternatively, if the value contains only single quotes or only double quotes, then you can use the other to delimit the attribute instead.

或者,如果该值仅包含单引号或双引号,则您可以使用另一个来分隔属性。

回答by Terry

As it's a form field, folks will type anything they like in there which may or may not include a nice mixture of double and single quotes. Adding these to the database is easy, escape them with " / ' etc.

由于它是一个表单字段,人们可以在其中输入他们喜欢的任何内容,其中可能包含也可能不包含双引号和单引号的完美组合。将这些添加到数据库很容易,用“/”等转义它们。

Nicely enough if you put " in the value clause of an input, it displays " on the screen as you want it to. Single quotes are a doddle, they can be as is if need be as their within doubles.

如果你把 " 放在输入的 value 子句中,它会根据你的需要在屏幕上显示 " 。单引号是轻而易举的,如果需要,它们可以原样作为双引号。