confirm/bind 사용법
if(confirm(" ?"))
{
// ,
}
bind: bind () 방법은 선택한 요소에 하나 이상의 이벤트 처리 프로그램을 추가하고 이벤트 발생 시 실행되는 함수를 규정합니다.
$(selector).bind({event:function, event:function, ...})
$(selector).bind(event,data,function) data
여러 이벤트를 동시에 귀속할 수도 있고 하나를 귀속할 수도 있습니다. 형식이 다르기 때문에 한 개의 시형을 귀속할 수 있습니다. 예를 들어
$("button").bind("click",function(){})
, 여러 개의 시형을 귀속할 수 있습니다. $("#test").bind({change:function(){},click:function(){}});
다음은confirm과bind를 이용하여select를 수정할 때 취소를 누르면 이전의 상태로 돌아갑니다.<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript"> $(document).ready(function(){ $("#test").bind({ change:function(){ if(confirm(" ?")) { // } else { this.value = valueOfTest; } } , click:function(){ valueOfTest= this.value; } }); }); </script>
</head>
<body>
<select id="test">
<option value="1"> </option>
<option value="2"> </option>
<option value="3"> </option>
</select>
</body>
</html>