如何将图像添加到代码点火器中的分页按钮


How to add image to pagination buttons in Code Igniter

$config['prev_link']='Previous';
                $config['prev_tag_open']='<button type="button" style="border-radius:5px;">';
                $config['prev_tag_close']='</button>';

这是控制器中的代码。现在,我想向此按钮添加图像,该怎么做?如果我使用源设置为 base_url('path/to/file.png')的标签,我只会得到一个带有白色边框的空方块。有什么想法吗,谢谢?

将按钮放入容器中(让div)并用 ID 命名

<div id="pagin">
    <button>1</button>
    <button>2</button>
    ..................
    ..................
    <button>10</button>
</div>

现在只需使用此波纹管脚本。

<script>
    var img = <?= base_url('path/to/file.png'); ?>
    $('#pagin button').html('<img src="+img+" alt="image alt text">');
    // This will display the image on every button
    $('#pagin button:first-child').html('<img src="+img+" alt="image alt text">');
    // This will display the image only on the first button
    $('#pagin button:last-child').html('<img src="+img+" alt="image alt text">');
    // This will display the image only on the last button
    $('#pagin button:nth-child(2)').html('<img src="+img+" alt="image alt text">');
    // This will display the image only on the 2nd button
</script>
你可以

像这样用CSS来做到这一点:

由于您已经在使用内联css,因此可以执行此操作

$config['prev_link']='Previous';
                $config['prev_tag_open']='<button type="button" style="border-radius:5px;background-image: url("yourimage.png");">';
                $config['prev_tag_close']='</button>';

但是,我建议添加一个新类并为该类提供 css 属性。

$config['prev_link']='Previous';
                    $config['prev_tag_open']='<button type="button" class="pg-prev">';
                    $config['prev_tag_close']='</button>';

CSS 文件

 .pg-prev{
    border-radius:5px;
    background-image: url("yourimage.png");
    }

关系,我找到了一种方法:

$config['next_link']='Next<img src="'.base_url("/resources/images/next.png").'" width=20; height=20; style="vertical-align: middle; margin-left: 5px;"/>';

这很完美,谢谢你们的关注。