Javascript를 이용한 Confirm Dialog를 띄우는 방법입니다.


HTML 소스

<body>
  <button id="button">confirm</button>
  <h5 id="text">취소</h5>
</body>


Javascript 소스

<script type="text/javascript">
    document.getElementById("button").onclick = function() {
      var bool = confirm("yes or no");
      var text = document.getElementById("text");
      if (bool) {
        text.innerHTML = "확인";
      } else {
        text.innerHTML = "취소";
      }
    }
</script>


결과


소스 및 예제페이지 확인



블로그 이미지

알터.

,

Javascript와 jQuery를 이용한 클릭, 더블클릭 이벤트 소스입니다.


HTML소스 

<body>
  <button id="click">Click</button>
  <button id="dblclick">doubleClick</button>
</body>


Javascript 소스

<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
      $("#click").click(function() {
        alert("click");
      });
      $("#dblclick").dblclick(function() {
        alert("double click");
      });
    });
</script>


결과

소스 및 예제페이지 확인


블로그 이미지

알터.

,

Javascript와 jQuery를 사용한 Table 다중 선택 소스입니다.


html Table 생성

<body>
  <table class="selectTable">
    <thead>
      <tr>
        <td>title1</td>
        <td>title2</td>
        <td>title3</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>content1</td>
        <td>content2</td>
        <td>content3</td>
      </tr>
      <tr>
        <td>content4</td>
        <td>content5</td>
        <td>content6</td>
      </tr>
      <tr>
        <td>content7</td>
        <td>content8</td>
        <td>content9</td>
      </tr>
    </tbody>
  </table>
</body>


css 설정

<style>
    .selectTable {
      border: 1px solid #000000;
    }

    #select {
      background-color: #BDBDBD;
    }
</style>


javascript설정

<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
  var lastIndex = 0;

    $(document).ready(function() {
      $(".selectTable tbody tr").click(function() {
        var select = $(this);
        var index = select.index();
        select.attr("id", "select");
        if(!window.event.ctrlKey && !window.event.shiftKey) {
          select.siblings().removeAttr("id");
        } else if(window.event.shiftKey) {
          for(var i=Math.min(lastIndex, index);i<Math.max(lastIndex, index);i++) {
            $(".selectTable tbody tr").eq(i).attr("id", "select");
          }
        }
        lastIndex = index;
      });
    });
</script>


결과

추가 옵션


-블록지정 방지

<body oncontextmenu="return false" ondragstart="return false" onselectstart="return false">


소스 및 예제페이지 확인


블로그 이미지

알터.

,