簡體   English   中英

有沒有辦法用雙引號字符串設置javascript變量值?

[英]is there any way to set javascript variable value with double quote string?

問題是字符串值是一個動態值,有時我有帶雙引號字符的數據,所以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尋找” (第3段)
下划線的字指的是什么?

粗體文本有雙引號,所以輸入類型不能設置所有的字符串

有什么想法可以操縱這個嗎?

您可以在字符串中使用雙引號,您只需要使用\\字符將它們轉義即可。 請記住,如果字符串來自 api 或類似的東西,您可能需要編寫一些代碼來手動轉義它們。

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

您可以使用&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?"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM