Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从模式窗口运行javascript函数?_Javascript_Php_Ajax_Codeigniter 3 - Fatal编程技术网

如何从模式窗口运行javascript函数?

如何从模式窗口运行javascript函数?,javascript,php,ajax,codeigniter-3,Javascript,Php,Ajax,Codeigniter 3,我有一个select,它通过改变calc的值来执行一个函数 $("#modelo").change(function () { var id_modelo = $(this).val(); $.ajax({ type: "POST", url: "<?php echo base_url(); ?>cotizacion/getimages",

我有一个select,它通过改变calc的值来执行一个函数

$("#modelo").change(function () {
            var id_modelo = $(this).val();
            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>cotizacion/getimages",
                dataType: 'json',
                async: true,
                data: "id_modelo=" + id_modelo,
                beforeSend: function () {

                    //$('#msgUsuario').html('<span></span>');
                },
                success: function (data) {
                    $("#imagenesnaves").html(data);
                    $('#contenimages').show();
                }
            });
            return false;
        });
哪个运行以下方法 控制器

public function getImages() {
        $id_modelo = $this->input->post('id_modelo', TRUE);
        $imagenes = $this->Modelos_model->getImages($id_modelo);
        $output = NULL;
        if ($imagenes) {
            $index = 0;
            foreach ($imagenes as $fila) {
                $output .= '<div class="file-preview-thumbnails">
                                <div class="file-live-thumbs">
                                    <div class="file-preview-frame"  data-fileindex="4" data-template="image">
                                        <div class="kv-file-content">
                                            <img src="' . base_url() . 'uploads/' . $fila->name . '" class="kv-preview-data file-preview-image" style="width:auto;height:160px;">
                                        </div>
                                        <div class="file-thumbnail-footer">
                                            <div class="file-actions">
                                                <div class="file-footer-buttons">';
                                                    if ($fila->active == 1) {
                                                        $output .=  '<a href = "javascript:desactivar(' . $fila->id_imagen . ');" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Desactivar imagen">
                                                    <i class = "glyphicon glyphicon-remove text-danger"></i></a>';
                                                    } else {
                                                        $output .=  '<a id="work" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Activar imagen">
                                                    <i class = "glyphicon glyphicon-ok text-primary"></i></a>';
                                                    }
                                                 $output .= '</div>
                                                <div class="clearfix"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>';
                        $index ++;
            }
            $output .= '<div class="clear"></div>';
        } else {
            $output .= '<p>No hay imagenes disponibles para mostrar. Prueba agregando una.</p>';
        }
        echo json_encode($output);
    }
此方法将加载到视图中

<div id="contenimages" class="col-lg-12" style="text-align: center; display: none">
                <a data-toggle="modal" data-target="#events-imagenes">Ver imagenes</a>
                <div class="modal fade col-lg-12" id="events-imagenes">
                    <div class="modal-dialog" style=" width: 800px !important">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            </div>
                            <div class="modal-body clearfix" style="height: 95%; display: initial">
                                <div class=" kv-main">
                                    <div class="file-input ">
                                        <div class="file-preview">
                                            <div id="imagenesnaves" class=" clickable" tabindex="-1">
                                                <div class="clearfix"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="modal-footer" style="height: 10%; text-align: center">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
</div>
加载后,每个图像都有一个打开或关闭按钮

if ($fila->active == 1) {
$output .=  '<a href = "javascript:desactivar(' . $fila->id_imagen . ');" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Desactivar imagen">
<i class = "glyphicon glyphicon-remove text-danger"></i></a>';
} else {
$output .=  '<a id="work" type = "button" class = "kv-file-deactivate btn btn-xs btn-default" title = "Activar imagen">
<i class = "glyphicon glyphicon-ok text-primary"></i></a>';
}
并且函数是通过javascript运行的 将脚本添加到视图中


但是当模式窗口打开时,不要运行,它会是什么?

这是因为在AJAX获取DOM之前,DOM不存在。您需要使用$.on方法来执行此操作:

$("#modelo").change(function () { 
改为

$("#modelo").on('change', function () {

在Firefox或Chromeium中,使用F12打开控制台并查看是否出现错误,可能简单到:$modelo.changefunction{change to$modelo.on'change',function{没有错误,我以为会是JQuery,但是not@Farkie这不是问题所在,通过ajax加载图像是成功的,但是包含图像的div中的按钮不执行该函数JS@JayBlanchard是的,它是重复的$.clickable.onclick.act.function{var value=$this.attr'data-record-id';activatevalue;};谢谢
$("#modelo").on('change', function () {