有什么方法可以使用双引号字符串设置javascript变量值?

时间:2020-01-16 02:31:48

标签: javascript html

问题在于字符串值是一个动态值,有时我的数据带有双引号字符,因此javascript无法从数据中读取全部字符串值。

我进行了操作,将值放在html输入上,然后将变量设置为html输入值。 但是,我发现了同样的问题,如果该值具有双引号字符,则该变量不能使用所有值。 元素显示如下:

<input type="hidden" id="soal7" value="Boyolali regency is located in north of Solo and east of Merapi and Merbabu Mountains. This regency has been known for its production of fresh milk for a long time. No wonder, the cow statues adorn Boyolali town.<br>
There are six main cow statues in Boyolali. They are displayed in different places.However, the size is made bigger to catch the eye.<br>
Besides decorating the town, the statues also turn out to be helpful for people from out of town to find places they are seeking in Boyolali. By mentioning the position of the statue, people can get their way easily.<br><br>" ...="" <u=""> they are seeking in Boyolali" (paragraph 3)<br>What does the underlined word refer to?">

该值必须为

Boyolali摄政区位于Solo北部和Merapi和Merbabu山以东。这个摄政区以生产鲜牛奶而闻名。难怪,牛雕像装饰着博伊奥拉利镇。
博伊奥拉利有六个主要的牛雕像。它们显示在不同的位置。但是,尺寸变大了以吸引眼球。
除了装饰城镇外,这些雕像还有助于外地居民在博伊奥拉利寻找他们想要的地方。通过提及雕像的位置,人们可以轻松上路。

“他们正在博伊拉利寻找” (第3段)
带下划线的单词指的是什么?

粗体文本用双引号引起来,因此输入类型不能设置所有字符串

有什么想法可以操纵这个吗?

2 个答案:

答案 0 :(得分:0)

您可以在字符串中使用双引号,只需要使用\字符对其进行转义。请记住,如果字符串是从api或类似的东西传入的,则可能需要编写一些代码来手动对其进行转义。

const myString = '\"Hello\"';
console.log(myString);

答案 1 :(得分:0)

您可以为此使用&quot;

<input type="text" value="single ' and double &quot;"/>

这是您的代码的完整摘要。我将其从type="hidden"更改为type="text",以便您阅读。

<input type="text" id="soal7" value="Boyolali regency is located in north of Solo and east of Merapi and Merbabu Mountains. This regency has been known for its production of fresh milk for a long time. No wonder, the cow statues adorn Boyolali town.<br>There are six main cow statues in Boyolali. They are displayed in different places.However, the size is made bigger to catch the eye.<br>Besides decorating the town, the statues also turn out to be helpful for people from out of town to find places they are seeking in Boyolali. By mentioning the position of the statue, people can get their way easily.<br><br>&quot; ...=&quot;&quot; <u=&quot;&quot;> they are seeking in Boyolali&quot; (paragraph 3)<br>What does the underlined word refer to?"/>