Home  >  Article  >  Backend Development  >  单引号和双引号

单引号和双引号

WBOY
WBOYOriginal
2016-06-23 13:22:251134browse


怎么给All加个引号?

+"<div class='read' id='read2'><a href='javascript:;' onclick='getCategory2(All,"+pages+")' >READ MORE</a></div>"+


我试着用反斜杠给它加上引号但是没用
onclick='getCategory2("+"\'"+"All"+"\'"+","+pages+")'  


回复讨论(解决方案)

 onclick='getCategory2(\"All\","+pages+")' 

+"



READ MORE
"+

var category="\"All\"";onclick='getCategory2("+category+","+pages+")' 这样可以了var category="\'All\'";  //改成单引号就不行了,Why?

 onclick='getCategory2(\"All\","+pages+")' 



+"



READ MORE
"+

为什么改成单引号就不行了呢?

因为你的分界符是双引,如果你使用单引,onclick=' 这里也是单引。
用单引包含单引会导致语法错误。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn