document.getElementById(" popup_upload")。style.display =' none not working

时间:2016-07-11 04:25:54

标签: javascript jquery codeigniter

当我试图上传非图像文件时,我想要隐藏我的弹出窗口。但是我在弹出框中单击上传照片按钮,显示加载符号并且执行在该语句处停止。这是我的code.in控制台我得到一个错误popup_upload没有定义。请给我一个解决这个问题的方法......多亏了所有提前

     function addAvathar() {

    $imgtype=$_FILES['userfile']['name'];
    $imext=explode('.',$imgtype);
    $ext=end($imext);
    if(($ext!='gif')&&($ext!='jpeg')&&($ext!='png')&&($ext!='jpg'))
   {

        echo '<script type="text/javascript">document.getElementById("popup_upload").style.display = "none";alert("upload correct file type");</script>';

           exit();
   }
   else{
    $config['upload_path'] = './avatar/';
    $config['allowed_types'] = 'gif|jpeg|png|jpg';
    $config['max_size'] = '1024mb';
    $config['max_width'] = '3000';
    $config['max_height'] = '3000';
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload()) {

        $ve['data'] = $this->upload->display_errors();
    } else {
        $this->upload->data();
    }


    if ($this->input->post("submit")) {
        $title = $this->input->post('title');

        $fInfo = $this->upload->data();

        if ($fInfo['image_width'] > 600) {
            $src = './avatar/' . $fInfo['file_name'];
            $percent = 0.5;
            $width = $fInfo['image_width'];
            $height = $fInfo['image_height'];
            $newwidth = $width * $percent;
            $newheight = $height * $percent;

            // Load
            $thumb = ImageCreateTrueColor($newwidth, $newheight);
            $extention = $fInfo['file_ext'];

            // create new jpeg image based on the target sizes

            switch ($extention) {
                case 'jpg':
                    $img_r = imagecreatefromjpeg($src);
                    break;
                case 'jpeg':
                    $img_r = imagecreatefromjpeg($src);
                    break;
                case 'png':
                    $img_r = imagecreatefrompng($src);
                    break;
                case 'gif':
                    $img_r = imagecreatefromgif($src);
                    break;
                default:
                    $img_r = imagecreatefromjpeg($src);
            }

            // Resize
            imagecopyresized($thumb, $img_r, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

            imagejpeg($thumb, $src, 90);
        }

        $ban = array('id' => '', 'title' => $title);
        $this->db->insert('bannar', $ban);
        echo '<script type="text/javascript">window.top.window.show_popup_crop("../../avatar/' . $fInfo['file_name'] . '")</script>';
    } else {
        $this->load->view('crop', array('edt' => $edit['result'], 'result' => $data['result']));
    }
   }
}

1 个答案:

答案 0 :(得分:0)

在PHP脚本中,如果您使用任何HTML标记意味着您可以在PHP脚本中运行javascript,如下面的代码。

echo "<div id='popup_upload'></div>";
echo "<script type='text/javascript'>document.getElementById('popup_upload').style.display = 'none';alert('upload correct file type');</script>";

然后只有脚本可以在HTML行中找到提到的id。更好的是,您可以在PHP中返回错误消息并将其显示在前端HTML文件中。