jeasyui - 如何用图像替换文本

时间:2014-01-24 22:12:25

标签: javascript jquery

jeasyui有没有办法用图像替换文字?我需要在状态下的所有结果中将图像替换为“是”和“否”。这就是我所拥有的:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script>
<script type="text/javascript">
$(function(){
    $('#dg').datagrid({
        view: detailview,
        detailFormatter:function(index,row){
            return '<div class="ddv"></div>';
        },
        onExpandRow: function(index,row){
            var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv');
            ddv.panel({
                border:false,
                cache:false,
                href:'show_form_RO.php?ID='+row.ID,
                onLoad:function(){
                    $('#dg').datagrid('fixDetailRowHeight',index);
                }
            });
            $('#dg').datagrid('fixDetailRowHeight',index);
        },
        rowStyler:function(index,row){
            if (row.Status=='No'){
                return 'background-color:pink;color:blue;font-weight:bold;';
            }
        }
    });
});
</script>

</head>
<body>
    <table id="dg" style="width: 1100px; height: 550px" url="get_records.php" toolbar="#toolbar"
        pagination="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="Checkedby" width="50" sortable="true">
                    Checked By
                </th>
                <th field="Status" width="50" sortable="true">
                    Successful?
                </th>
                <th field="Date" width="50" sortable="true">
                    Date
                </th>
                <th field="Notes" width="50">
                    Explain if backup failed
                </th>
            </tr>
        </thead>
    </table>

我尝试将此脚本添加到头部,但它不起作用:

<script type="text/javascript">
    $("#dg:contains('1')").html(function (_, html) {
     return html.replace(/\b1\b/,"<img src='images/ok.png' />");
});
    $("#dg:contains('-1')").html(function (_, html) {
     return html.replace(/-1/,"<img src='images/fail.gif' />")
});
</script>

感谢您的帮助。

0 个答案:

没有答案