내 질문 : 왜 함수 호출 $ ( "# p1"). click () 사용자가 "p1"을 클릭하도록 시뮬레이션하지 않습니까? 즉 "$ (this) .hide ()는 전혀 실행되지 않습니다.
하지만 $ (document) .ready (function () {});에 클릭 이벤트를 등록하면 $ ( "# p1"). click ()이 작동합니다! 왜?
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$("#p1").click(function(){
$(this).hide();
});
$(document).ready(function(){
$("#p1").click(); <== this line doesn't work! why?
});
</script>
</head>
<body>
<p id="p1">If you click on me, I will disappear.</p>
</body>
</html>
#p1
click 이벤트를 첨부 할 때 요소 가로드되지 않기 때문입니다 .
$(document).ready(function(){
$("#p1").click(function(){
$(this).hide();
});
$("#p1").click();
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다