javascript - 在 WordPress 选项页面的第一行使用 colspan 制作一行

标签 javascript jquery wordpress html-table meta-boxes

在我的 WordPress 选项页面中,为了创建我正在使用的字段 Fluent Framework 。它类似于 Meta Box 。所以他们都使用 do_settings_fields 函数,该函数生成如下代码:

<table class="form-table">
<tr>
    <th scope="row">Header 1</th>
    <td>Element 1</td>
</tr>
<tr>
    <th scope="row">Header 2</th>
    <td>Element 2</td>
</tr>
<tr>
    <th scope="row">Header 3</th>
    <td>Element 3</td>
</tr>
<tr>
    <th scope="row">Header 4</th>
    <td>Element 4</td>
</tr>
</table>

它看起来像这样: enter image description here

在此表中,我想将第一行用作一行,如下所示:

enter image description here

我在 fields/custom_html 目录中创建了一个 javascript 文件,并使用 jQuery 隐藏范围,并将 javascript 文件排入队列,如下所示:

jQuery(document).ready(function()
{
    jQuery('th[scope="row"]').first().hide();
});

但这并不能完全解决我的问题。因为我不介意只使用一行,但是对于多行来说就很成问题了。也许我需要关闭 table 标签并再次打开一个新的 table 标签,但由于我有限的 jQuery 知识,我无法做到这一点。

最佳答案

合并两列时,您必须使用“colspan”属性,这会很有帮助,这里我分享 jquery 的代码。

$(document).ready(function(){
  var $table_head = jQuery('tr').first();
  var value = $table_head.text();
  $table_head.html('<th colspan="2">'+value+'</th>');
});

关于javascript - 在 WordPress 选项页面的第一行使用 colspan 制作一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54861582/

相关文章:

php - WordPress 自定义短代码破坏了保存过程(post.php)

javascript - 需要 WeakMap (a, b) -> c

javascript - ASP.NET MVC 中的自定义输入格式

javascript - 隐藏 div(仅包含 script 标签)

javascript - 为什么 url 查询字符串不传递变量值?

javascript - 精简 IF 语句,看起来有点过头了

php - Wordpress wpdb->从表单准备 sql 字符串

javascript - 在 jQuery 中通过 granim.js 使用 CMS 数据

javascript - firebase firestore 和 grpc 中未建立连接错误

javascript - 使用 jQuery 突出显示搜索词,例如 Chrome