EasyUI的图片显示————formatter属性

JavaScript部分

function formatImg(value,row,index){
    
    if(value){
        return "<img src='${pageContext.request.contextPath }/img/"+value+"' style=width:80px;height:50px;>"
        
    }else{
        return null;    
    }
}

注: ${pageContext.request.contextPath }  这个是绝对路径。

有些时候不写这行代码也可以展示出图片,而最好将这行写上为好,我就有一次没写上,然后没显示出图片,而同事也没写他的反而可以显示出图片,之后我加上了这行代码,我的也可以显示图片了。

JSP页面部分

<th data-options="field:'pimg',width:50,align:'right',align:'center',formatter:formatImg">图片</th>

猜你喜欢

转载自blog.csdn.net/zhang1409399037/article/details/83899456
今日推荐