[jQuery] HTML에서 onClick으로 jQuery 호출방법
Calling jQuery method from onClick attribute in HTML
jQuery 에서 HTML태그안에 onClick 이벤트로 파라미터 넘기기 1
jQuery Function 은 이렇게
function showMessage(msg) {
   alert(msg);
};HTML 은 요렇게
<html>
<head>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
 <script language="javascript">
    // define the function within the global scope
    $.fn.MessageBox = function(msg) {
        alert(msg);
    };
// or, if you want to encapsulate variables within the plugin
    (function($) {
        $.fn.MessageBoxScoped = function(msg) {
            alert(msg);
        };
    })(jQuery); //<-- make sure you pass jQuery into the $ parameter
 </script>
</head>
<body>
 <div class="Title">Welcome!</div>
 <input type="button" value="ahaha" id="test" onClick="$(this).MessageBox('msg');" />
</body>
</html>
'Web > javascript / jQuery' 카테고리의 다른 글
| [jQuery] 날짜 포맷팅 date formatting (2) | 2015.04.28 | 
|---|---|
| [jQuery] .click 으로 파라미터 넘기기 (2) | 2015.04.28 | 
| [jQuery] 문자열 배열에서 중복되는 값들 없애주는 방법 (2) | 2015.04.27 | 
| [jQuery] 텍스트박스에서 엔터키 인지 및 동작하기 (2) | 2015.04.27 | 
| [jQuery] 셀렉트박스안의 모든 옵션의 value 를 가져오는 방법 (2) | 2015.04.27 |