简体   繁体   English

Yii2下拉活动表单上的错误调用函数

[英]Error Call Function On Yii2 Dropdown Active Form

Halo, I using Yii2 and I get error while call a function in dropdown list. 晕,我使用Yii2,在下拉列表中调用函数时出错。

This is my dropdown : 这是我的下拉菜单:

<?= $form->field($model, "jenis_manifest")->dropDownList([ 'Berangkat' => 'Berangkat', 'Pulang' => 'Pulang'], ['onchange' => 'fungsiUtama();', 'class' => 'form-control', 'prompt' => '-- Manifest --']) ?>

And this is my script : 这是我的脚本:

<?php

    $script = <<<JS
    function fungsiUtama()
    {
        alert("Hello");
    }
    JS;

    $this->registerJs($script);
?>

I also try with JsExpression base on this question , but still not working. 我也基于此问题尝试使用JsExpression,但仍然无法正常工作。

This is the error what I get : 这是我得到的错误: 在此处输入图片说明

Use 采用

$this->registerJs($script, \yii\web\View::POS_END);

The last part means - add this script straightforward at the end of page. 最后一部分意味着-在页面末尾直接添加此脚本。

Without the second function argument the default one is called - \\yii\\web\\View::POS_READY - which means - add this script wrapped in jQuery(document).ready() method that forces scripts to wait untill the page's DOM is fully loaded. 如果没有第二个函数参数,则默认名称为- \\yii\\web\\View::POS_READY这意味着-将此脚本添加到jQuery(document).ready()方法中,以强制脚本等待页面的DOM被完全加载为止。 Before that your script is unavailable and that is probably why you've got this error. 在此之前,您的脚本不可用,这可能就是您收到此错误的原因。

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

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