2014-02-21 2 views
0

여러 개의 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 코드입니까? 모든 조언을 감사하십시오.

+0

충돌해야하는 이유는 없습니다. 어떻게 그들을 "부르다"는거야? 호출 할 명명 된 함수가 없습니다. – Barmar

+0

PHP 클래스입니까? 왜냐하면 당신은'$ this'를 호출하기 때문입니다. JS와 PHP의 출력이 유효합니까? – vonUbisch

+0

나는 그들을 클릭 버튼에 기반하여 호출하고 있습니다. – user3192948

답변

0

PHP를 통해 모든 .js 파일을 실행하도록 서버를 구성하지 않았다면이 파일을 외부 .js 파일로 옮기면 평가되지 않을 것입니다.

+0

당신이 옳다고 생각합니다. 어떻게 든 외부 HTML에 mthe html에서 이러한 변수를 전달할 수있는 방법이 있나요? – user3192948

+0

그것들은 전역 변수이므로 두 개의 ''줄을 PHP 파일에 넣으면됩니다.이 줄은 이후에 포함 된 모든 JavaScript에서 사용할 수 있습니다. – meagar

관련 문제