1
場景: 雙引號後,下一個字符不顯示。div文本到輸入值
我知道這是因爲單引號和雙引號的轉義,我試過這個正則表達式(/"/g,'\"')
,但它不工作。
有人可以幫我查看代碼嗎?我想要的輸出是div上的所有字符也應顯示在輸入上。
PS:我想盡可能避免replace(/"/g,'"')
。
<div>single ' double " single ' </div>
<form>
</form>
$("form").append('<input type="text" value = "' + $("div").text().replace(/"/g,'\"') + '" />');
看到這個小提琴demo
如果我需要添加其他元素,這是適當的格式? http://jsfiddle.net/3uc4fLeh/9/ – bumbumpaw
jQuery的['.append()'](http://api.jquery.com/append/)確實支持這種格式('.append(content [,content] )');但說實話,對我來說,這很難閱讀。您可以製作上述代碼的另一個副本以添加第二個輸入。如果像這樣http://jsfiddle.net/3uc4fLeh/10/, – Mottie
格式變得複雜。任何其他想法?無論如何,謝謝你的信息!這對我來說是新的。 @Mottie – bumbumpaw