http://jsfiddle.net/ZBaWd/는 on
핸들러를 사용하는 방법을 보여줍니다.
<div id="container"></div>
var cont = $("#container");
// Note that I'm attaching it to container and not the forms themselves.
// Then, as an additional parameter, I provide the selector "form" so that
// `on` is only fired for "form" elements that "submit" and are children of "#container"
$("#container").on("submit", "form", function(e){
e.preventDefault();
console.log($(this));
});
$("<form>").addClass("form_one").append("<button type='submit'>Submit 1</button>").appendTo(cont);
$("<form>").addClass("form_two").append("<button type='submit'>Submit 2</button>").appendTo(cont);
1)'live'는 더 이상 사용되지 않으며'on'을 대신 사용하십시오. 2) 왜 .form_two를 추가합니까? '$ ('.form_one, .form_two'). on ... ' – Shmiddty
양식을 동적으로 추가하지 않으면'$ ('. form_one, .form_two ')로 작성할 수 있습니다. submit (function() ... ' – Shmiddty
'on'은 제 경험상 완벽하지 않았습니다. 잘못 사용했을 수도 있지만,이 경우'live'를'on'으로 바꾸면 크롬에서 작동하지 않습니다 . –