今天在做手工時,忽然被一個小東西卡住:
在javascript裡組字串時,我要怎麼組出原本需要的單引號?
例如:
let stringHtml = ' <div id="' + ID + '"> ';
stringHtml += '<button class="btn" onclick="clickfun(\' ' + funID + '\')">按我</button>';
stringHtml += ' </div> ';
組字串時用單引號包住內容=> '內容'
要斷行時用+號 => stringHtml += '字串' 或是 stringHtml = stringHtml + '字串'
記得每個斷行都要有 分號 ;
but 單引號怎麼辦..只用單一個是認不出來的 ,
如果要顯示單引號就要加點料 => \' 先來個反斜線再加上單引號就可以開開心心的顯示出來了!
沒有留言:
張貼留言