if(!a) a=="" || a >0的时候执行
文字超过展开与收起
相关文章:https://blog.csdn.net/erdouzhang/article/details/71105188
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// 截断字符串 function init(){ var len = 84; //默认显示字数 var ctn = document.getElementById("introDetail"); //获取div对象 var content = ctn.innerHTML; //获取div里的内容 //alert(content); var span = document.createElement("span"); //创建<span>元素 var a = document.createElement("a"); //创建<a>元素 span.innerHTML = content.substring(0,len); //span里的内容为content的前len个字符 a.innerHTML = content.length>len?"... 展开":""; ////判断显示的字数是否大于默认显示的字数 来设置a的显示 a.href = "javascript:void(0)";//让a链接点击不跳转 a.onclick = function(){ if(a.innerHTML.indexOf("展开")>0){ //如果a中含有"展开"则显示"收起" a.innerHTML = "<< 收起"; span.innerHTML = content; }else{ a.innerHTML = "... 展开"; span.innerHTML = content.substring(0,len); } } // 设置div内容为空,span元素 a元素加入到div中 ctn.innerHTML = ""; ctn.appendChild(span); ctn.appendChild(a); } init()
跨域访问限制
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Headers:content-type");
header("Access-Control-Request-Method:GET,POST");
if(strtoupper($_SERVER['REQUEST_METHOD'])== 'OPTIONS'){
exit;
}
header("Access-Control-Allow-Headers:content-type");
header("Access-Control-Request-Method:GET,POST");
if(strtoupper($_SERVER['REQUEST_METHOD'])== 'OPTIONS'){
exit;
}