jQuery 코드가 예상대로 작동하지 않습니다. 삭제 및 이동 : 두 개의 유사한 코드 블록이 있습니다jQuery show()가 Chrome에서 작동하지 않습니다.
$(function() {
// delete file
$("a.delete_file_initial").click(function(event) {
event.preventDefault()
$(this).hide()
$(".delete_file_question").show()
});
$("a.delete_file_question").click(function(event) {
if ($(this).hasClass("cancel")) {
event.preventDefault()
$(".delete_file_question").hide()
$(".delete_file_initial").show()
}
});
// move file
$("a.move_file_initial").click(function(event) {
event.preventDefault()
$(this).hide()
$(".move_file_question").show()
});
$("a.move_file_question").click(function(event) {
if ($(this).hasClass("cancel")) {
event.preventDefault()
$(".move_file_question").hide()
$(".move_file_initial").show()
}
});
});
:
<a href="">Some link</a>
<br/>
<a class="delete_file_initial" href="">Delete file</a>
<span class="delete_file_question hide">are you sure to delete?</span>
<a class="delete_file_question confirm hide" href="http://example.com/delete">yes</a>
<a class="delete_file_question cancel hide" href="">no</a>
<br/>
<a class="move_file_initial" href="">Move file</a>
<span class="move_file_question hide">are you sure to move?</span>
<a class="move_file_question confirm hide" href="http://example.com/move">yes</a>
<a class="move_file_question cancel hide" href="">no</a>
그리고 자바 스크립트 : 여기
는 HTML입니다. 로드 할 실제 URL이 다르다는 것을 제외하고는 동일한 작업을 수행해야합니다. 예상되는 동작은 다음과 같습니다. 사용자가 "삭제"/ "이동"링크를 클릭하면 확인 링크가 표시되고 해당 작업을 확인 또는 취소합니다."delete_file_initial"링크를 클릭하면 숨겨 지지만 "delete_file_question"링크가 표시되지 않고 빈 줄이 남습니다. "이동"블록이 예상대로 작동합니다. 그리고 "이동"블록에 주석을 달면 "삭제"블록이 예상대로 작동하기 시작합니다. 더욱 놀라운 것은이 버그가 Chrome 22.0.1229.79에 나타나지만 Firefox 15.0.1에서는 모든 것이 정상적으로 작동한다는 것입니다.
이 버그를 해결하는 방법?
크롬 22 절은 나에게 문제가 제공되지 않습니다 http://jsfiddle.net/mblase75/cg8Sh/ - 콘솔에 오류가 있습니까? 하나의 생각 :'href' 속성은 절대로 비어서는 안됩니다. [필요할 경우 "빈 href"로'#'또는'javascript :를 사용하십시오.] (http://jsfiddle.net/mblase75/cg8Sh/3/) (자바 스크립트 행을 세미콜론으로 끝내는 것도 좋은 습관입니다. .) – Blazemonger
코멘트 주셔서 감사합니다. 아니요, 콘솔에 오류가 없습니다 (문제가되는 '
'을 html에 추가 한 후에도 내 대답 참조). jquery 버그가 될 수 있습니까 (1.4.4를 사용하고 있습니다)? –