https://files.cnblogs.com/files/cnsevennight/verdant.css

easyuI企业管理系统-实战四 上传图片

今天你学习了吗?本篇实例上传图片,需要注意的是ID名称不要出现重复,否则运行时会被误导,增加自己的调试bug时间。
<form enctype="multipart/form-data" id="fm4" method="post" novalidate minimizable > <input type="file" name="upload" id="upload1" class="easyui-validatebox" validType="fileType['BMP|GIF|JPG|JPEG|ICO|PNG|TIF']" invalidMessage="请选择(BMP|GIF|JPG|JPEG|ICO|PNG|TIF)等格式的图片"/> <a href="javascript:void(0)" id="category_image3" class="easyui-linkbutton my-dialog-button" type="submit" plain="true" icon="icon-ok" onclick="saveuser3()" iconcls="icon-save">上传</a> </form>
//上传图片
    function saveuser3(){
        var nameValue1=window.document.getElementById("category_image3").value; 
        //alert(nameValue1);
            if (nameValue1 == "")
            {
                window.alert("上传失败! 请重新选择图片");
                return false;
            }   
            else
            {
            if(/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(nameValue1))
                {
                  alert("图片类型必须是.gif,jpeg,jpg,png中的一种")
                  return false;
                }
            }
        $("#fm4").form("submit", { 
            url: '{:U('Inter/admin/general_upload')}',  
            success: function (result) {  
                    if (result) {     
                            edit2(result);                    
                            }
                    else {
                            $.messager.alert("提示信息", "添加不成功"); 
                            }  
                    }   
                });  
        }      
    //保存上传图片的路径
    function edit2(result) { 
                $("#dlg").dialog("open").dialog('setTitle', '分类相关信息'); 
                $('#category_image').val(result.replace('{"result":',"").replace("}",""));
                $("#fm").form("load", row);
    }     
    function saveEdit2() {         
        $("#fm").form("submit", {
            url: '{:U('Inter/admin/category_create')}', 
            success: function (result) {
                    if (result) {
                            $.messager.alert("提示信息", "添加成功");   
                            $("#dlg").dialog("close");   
                            $('#tt').datagrid('reload');}
                    else { 
                            $.messager.alert("提示信息", "添加不成功");                               
                        }  
                    }         
                });  
        } 

 

posted @ 2015-10-19 16:44  imemy计算机毕设  阅读(364)  评论(0编辑  收藏  举报