Переместить код js со страницы html в файл js и вызвать этот код на моей странице html - PullRequest
0 голосов
/ 16 ноября 2018

Привет, ребята. Я пытаюсь переместить мой 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.

Может кто-нибудь помочь мне, как я могу это сделать. Заранее спасибо.

1 Ответ

0 голосов
/ 16 ноября 2018

как только вы предоставили дополнительную информацию (первоначальный запрос был вне контекста), вот что-то похожее на ваш пример:

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();
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...