将 js 代码从 html 页面移动到 js 文件并在我的 html 页面中调用该代码

Move js code from html page to js file and call that code in my html page

大家好,我正在尝试将我的 js 代码从我的 phtml 页面移动到 js 页面,我想将该页面调用到我的 phtml 页面中。我在 zend 工作。

任何人都可以帮助我,我该怎么做。

这是我的 phtml 代码:

   <div class="reminderForm">
    <form id="reminderForm_<?php echo $this->ticketId;?>">
        <h4><?php echo $this->translate('set_reminder'); ?></h4>
        <span class="formz-required">*</span>
        <?php echo $this->form->remark;?>
        <?php if ($this->isAllowed('ticket.index.reminder-type')) : ?>
            <span class="remark-element-span formz-required">*</span>
            <?php echo $this->form->reminderType;
        endif; ?>
        <span class="remark-element-span formz-required">*</span>
        <?php
            echo $this->form->reopenTicket;
            echo $this->form->ticketId; 
        ?>
        <div class="button-block">
            <span><?php echo $this->form->cancel; ?></span>
            <span><?php echo $this->form->save; ?></span>
        </div>
    </form>
</div>
<?php 
echo $this->inlineScript()->appendScript(<<<EOS
    $(".reopenTicket").datetimepicker({
        showOn: "button",
        buttonImage: "/themes/bas/icons/fatcow/16x16/calendar.png",
        dateFormat:'dd-mm-yy',
        timeFormat: 'HH:mm',
        buttonImageOnly: true, 
        controlType: 'select',
        showWeek: true,
        firstDay: 1,
        oneLine : true
    });
    var today = new Date();
    var tomorrow = new Date(); 
    tomorrow.setDate(today.getDate()+1);
    tomorrow.setHours(8);
    tomorrow.setMinutes(0);
    $(".reopenTicket").datetimepicker("setDate", new Date(tomorrow));
EOS
);
?>

这是我的 js 文件:

    var REMINDER = {};

REMINDER.Followupreminder = {

};

在那里面

 REMINDER.Followupreminder = {

};

函数我想调用那个 js 代码。

任何人都可以帮助我,我该怎么做。 提前致谢。

一旦您提供了额外的信息(最初的请求是断章取意的),这里有一些与您的示例类似的信息:

var REMINDER = {};

REMINDER.Followupreminder = {

    init: function(){
        // put your any initialization here
        this.bindUI();
    },

    bindUI: function(){
        // if bindUI isn't being used from outside - you may call this.initDatePicker() directly from init()
        this.initDatePicker();
    },

    initDatePicker: function () {
        console.log('Congratulations! Your code has been moved and executed!');
        $(".reopenTicket").datetimepicker({
            showOn: "button",
            buttonImage: "/themes/bas/icons/fatcow/16x16/calendar.png",
            dateFormat: 'dd-mm-yy',
            timeFormat: 'HH:mm',
            buttonImageOnly: true,
            controlType: 'select',
            showWeek: true,
            firstDay: 1,
            oneLine: true
        });
        var today = new Date();
        var tomorrow = new Date();
        tomorrow.setDate(today.getDate() + 1);
        tomorrow.setHours(8);
        tomorrow.setMinutes(0);
        $(".reopenTicket").datetimepicker("setDate", new Date(tomorrow));
    }
};

$(function(){
    REMINDER.Followupreminder.init();
});