카테고리 없음2013. 6. 14. 12:10

jQuery를 사용하면 (만들기) HTML 콘텐츠를 추가할 수 있습니다. 예를 들어 여기서 각 'div'요소에 일부 HTML을 추가하려면 jquery를 사용하여 할 수 있습니다. 

 

<!DOCTYPE html>
<html>
<head>
<style>
   .red { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<span>Hello</span>
<div></div>
<div></div>
<div></div>
<script>$("div").html("<span class='red'>Hello <b>Again</b></span>");</script>
</body>
</html>

OUTPUT

 

여러분은 jQuery를 사용하여 HTML을 받을 수 있으며 그것을 수정할 수 있습니다 예를 들어, 클릭과 텍스트로 HTML에서 변환할 수 단락을 얻을 수 있습니다. :

 

<!DOCTYPE html>
<html>
<head>
  <style>
  p { margin:8px; font-size:20px; color:blue;
      cursor:pointer; }
  b { text-decoration:underline; }
  button { cursor:pointer; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<p>

    <b>Click</b> to change the <span id="tag">html</span>
  </p>
  <p>

    to a <span id="text">text</span> node.
  </p>
  <p>
    This <button name="nada">button</button> does nothing.
  </p>
<script>
    $("p").click(function () {
      var htmlStr = $(this).html();
      $(this).text(htmlStr);
    });
</script>
</body>
</html>

 

OUTPUT :

The page looks like :

 

click 를 클릭하면  

로 바뀌어진다.

 

또한 일치하는 요소에 HTML 콘텐츠를 설정할 수 있습니다. 예를 들어, 각각의 필터 elememts에 HTML 콘텐츠를 설정할 수 있습니다 :

 

<div class="demo-container">
<div class="demo-box">Demonstration Box</div>
</div>

 

You can set the html content inside 'demo-box' div class using following code :

$('div.demo-container'>
.html('<p>All new content. <em>You bet!</em></p>');

The above line will change the content and produce output something like this :

<div class="demo-container">
<p>All new content. <em>You bet!</em></p>
</div>

Download Source Code

Posted by 아이맥스