最主要的一个,觉得脚本影响效率。想把两个脚本合并在一起,同样的风格。
代码一: | window.onload=function(){ | | JTsetup('x-hw'); | | iterationSetup(); | | specialSetup(); | | }; | | | | function specialSetup(){ | | var _xa=document.querySelectorAll('x-a'); | | if(!_xa[0]) return; | | for(var i=0; i<_xa.length; ++i) | | _xa[i].parentNode.setAttribute('x-meaning', ''); | | } | | | | function iterationSetup(){ | | var _hw=document.querySelectorAll('x-hw'); | | if(_hw.length<2) return; | | for(var i=0; i<_hw.length; ++i){ | | var _it=document.createElement('sup'); | | _it.textContent=(i+1); | | _hw[i].appendChild(_it); | | } | | } | | | | function JTsetup(str){ | | var _eles=document.querySelectorAll(str); | | if(_eles.length<2){ | | if(!!_eles[0]){ | | _eles[0].removeAttribute('onclick'); | | } | | return; | | } | | for(var i=0; i<_eles.length; ++i){ | | _eles[i].setAttribute('onclick', scrollPosition(_eles[i==_eles.length-1?0:i+1])); | | } | | } | | | | function scrollPosition(target){ | | var _id=target.getAttribute('id'); | | if(!_id){ | | _id='random'+Math.round(Math.random()*1048576); | | target.setAttribute('id', _id); | | } | | if(!isBluedict()) | | return "window.location.href='#"+_id+"'"; | | return "window.location.href='entry://#"+_id+"'"; | | } | | | | function isBluedict(){ | | return !!document.querySelector('.bd_body'); | | }COPY |
代码二: | window.onload = function(){ | | if(document.getElementById("img_ysxs")){ | | document.getElementById("img_ysxs").style.maxWidth="100%"; | | document.getElementById("img_ysxs").onclick=function(){ | | var now = document.getElementById ("img_ysxs"); | | var i = now.style.maxWidth | | if(i=="100%"){document.getElementById("img_ysxs").style.maxWidth="none";}else{document.getElementById("img_ysxs").style.maxWidth="100%";} | | }; | | }; | | if(document.getElementById("img_zxyb")){ | | document.getElementById("img_zxyb").style.maxWidth="100%"; | | document.getElementById("img_zxyb").onclick=function(){ | | var now = document.getElementById ("img_zxyb"); | | var i = now.style.maxWidth | | if(i=="100%"){document.getElementById("img_zxyb").style.maxWidth="none";}else{document.getElementById("img_zxyb").style.maxWidth="100%";} | | }; | | }; | | };COPY |
|