javascript - Javascript函数中的多个ID
问题描述
我有多个具有不同 ID 标签的数据表,如果存在多个 ID,我正在尝试让 JavaScript 文件应用样式。
这是我所拥有的不起作用的:
$(function() {
$("[id*=tblAccount") || ("[id *= tblCustomer") || ("[id *= tblContact").prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"dom": 'lBfrtip',
"buttons": ['excel', 'print', 'pdfHtml5']
});
})
解决方案
您需要使用 CSS 选择器运算符在对 jQuery 的一次调用中组合选择器,
:
$("[id*=tblAccount], [id *= tblCustomer], [id *= tblContact]").prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({
(另请注意,我添加了缺少的]
字符。)
推荐阅读
- solr - SOLR ComplexPhrase Range 查询问题
- azure - 如何在数据工厂中使用 Databricks 现有集群 ID 的参数?
- sql - 升级到 PostgreSQL 11:CASE 中不允许使用 set-returning 函数
- mongodb - MongoDB Charts 是否解析 DBRefs?
- javascript - 如何从js函数中获取php变量
- php - 如何从 API 获取数据并将其显示在 PHP 页面上?
- vert.x - Vert.x-Web 的 setChunked 方法的实际应用是什么?
- twilio - 如何将 twiml 发送到正在进行的呼叫
- php - 在执行脚本之前尝试重定向用户不起作用
- google-cloud-platform - 在 Cloud Function 中验证 Google 管理员身份