JS 고급 - 샌드박스 케이스

3037 단어

샌드박스 케이스


 
substr 캡처, 지정한 필드부터 캡처하기
    (function () {
      var str=" ";
      str=str.substr(2);
      console.log(str);
    }());

 
substr 캡처, 지정한 필드부터 캡처하기
    // 
    (function () {
      var str=" ";
      str=str.substr(2);
      console.log(str);
    }());

 
샌드박스 사례, 페이지 요소 조작
 
div
div
div

p

p

p

<span style="color: #0000ff;">var</span> getTag = 10<span style="color: #000000;">; </span><span style="color: #0000ff;">var</span> dvObjs = 20<span style="color: #000000;">; </span><span style="color: #0000ff;">var</span> pObjs = 30<span style="color: #000000;">; (</span><span style="color: #0000ff;">function</span><span style="color: #000000;"> () { </span><span style="color: #008000;">//</span><span style="color: #008000;"> </span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> getTag(tagName) { </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> document.getElementsByTagName(tagName); } </span><span style="color: #008000;">//</span><span style="color: #008000;"> div</span> <span style="color: #0000ff;">var</span> dvObjs = getTag("div"<span style="color: #000000;">); </span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i = 0; i < dvObjs.length; i++<span style="color: #000000;">) { dvObjs[i].style.border </span>= "2px solid pink"<span style="color: #000000;">; } </span><span style="color: #008000;">//</span><span style="color: #008000;"> p</span> <span style="color: #0000ff;">var</span> pObjs = getTag("p"<span style="color: #000000;">); </span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i = 0; i < pObjs.length; i++<span style="color: #000000;">) { pObjs[i].style.border </span>= "2px solid pink"<span style="color: #000000;">; } }()); console.log(getTag); console.log(dvObjs); console.log(pObjs); </span>

좋은 웹페이지 즐겨찾기