1. 程式人生 > >javascript的單引號與雙引號

javascript的單引號與雙引號

   在JavaScript中單引號和雙引號區別不大,在表示字串中是完全等效的,如果在字串中存在單引號則外面就要用雙引號,如果字串中存在雙引號則在外面要用單引號括起來,這樣就不用轉義裡面的符號了, 不會出現錯誤了。

列如:

document.write('<font size="5" face="Arial"><b>'+(myDate.getMonth()+1)+"/"+myDate.getDate()+"/"+ myDate.getYear()+'</b></font><br/>');

或:

document.write(“<font size="5" face="Arial"><b>”+(myDate.getMonth()+1)+’/‘+myDate.getDate()+‘/’+ myDate.getYear()+“</b></font><br/>”);