繁体   English   中英

放置多个JS脚本1个JS文件

[英]Putting multiple JS scripts 1 one JS file

我将多个2个JS脚本放在一个文件中,尽管当它们包裹在html文件中的when时它们独立工作良好,但是当我从外部JS文件中调用它们时,第二个脚本根本无法工作。

这是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

是什么原因 感谢任何建议。

如果您将其中的PHP迁移到外部.js文件中,那么一堆PHP肯定不会被评估,除非您已将服务器配置为通过php运行所有.js文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM