여러 개의 JS 스크립트를 1 개의 파일에 넣을 수 있습니다. html 파일을 감쌀 때 독립적으로 작동하지만 두 번째 JS 파일은 호출 할 때 작동하지 않습니다. 외부 JS 파일에서. 원인이 무엇여러 개의 JS 스크립트 퍼팅 1 개의 JS 파일
// start of open the name div
$(function() {
$('.reply_submit_name_open').click(function(){
$(this).siblings('.reply_submit_name').fadeIn();
$(this).fadeOut();
});
$('.check_author').click(function(){
if($('.check_author').is(":checked")) {
$('.name_input').val($(this).val());
$('.name_input').attr('readonly', true);
} else {
$('.name_input').attr('readonly', false);
}
});
});
// end of opening name div
// start of posting replies
var base_url = '<?php print base_url();?>';
var interview_id = '<?php echo $this->uri->segment(3)?>';
$(function() {
$('.reply_button').click(function(){
var this_a = $(this);
var reply = $(this).parents().siblings('textarea').val();
var username =$(this).siblings().find('input').val();
var parent_comment_id=$(this).closest('form').attr('id');
var last_reply_id=$(this).closest('.reply_form_div').siblings('.replies').children().last('.comment').attr('id');
$.ajax({
type:"POST",
url: base_url + "comment_upload/reply_upload",
data:{parent_comment_id : parent_comment_id, interview_id: interview_id, reply:reply, username: username},
dataType: "json",
success: function(data,status){
if(data.state == 'succ') {
this_a.html('Success');
$('.reply_button').closest('.reply_form_div').siblings('.replies').append(data.new_reply);
} else {
this_a.html('Bad');
}
}
});
});
});
// end of posting replies
:
다음은 JS 코드입니까? 모든 조언을 감사하십시오.
충돌해야하는 이유는 없습니다. 어떻게 그들을 "부르다"는거야? 호출 할 명명 된 함수가 없습니다. – Barmar
PHP 클래스입니까? 왜냐하면 당신은'$ this'를 호출하기 때문입니다. JS와 PHP의 출력이 유효합니까? – vonUbisch
나는 그들을 클릭 버튼에 기반하여 호출하고 있습니다. – user3192948