HTML HTML表的Buggy CSS(示例)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTML HTML表的Buggy CSS(示例)相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>AR-omr-design-v2 (BETA)</title>
  <base href="file:///E:/sahwar's%20Labs/AnimeRulezzz/html%20and%20css%20for%20AR/AR-mangareader-table/"/> <!-- defines the master domain (offline, online) of/for relative links... -->
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <meta http-equiv="expires" content="-1" />
  <meta http-equiv= "pragma" content="no-cache" />
  <meta name="Various (AnimeRulezzz.org, sahwar, OmegaKO)" content="online manga reader redesign project animerulezzz.org" />
  <meta name="robots" content="all" />
  <meta name="MSSmartTagsPreventParsing" content="true" />
  <meta name="description" content="online manga reader redesign project animerulezzz.org." />
  <meta name="keywords" content="online, manga reader, redesign, project, animerulezzz.org, CSS, JavaScript, comic gallery, anime, buttons" />


<style type="text/css">

/* Begin FIXES AND MISCELLANEA */

table img {border:none; display:block; vertical-align: bottom;}
a img { border: none;}
img {display:block; border: none;}
table {border-spacing: 0px 0px;}
table tbody {border-top:none;}
div img {vertical-align: bottom;}

/* End FIXES AND MISCELLANEA */

/* Begin MAIN PART */

/* table1 BEGIN */
table.gridtable1 {
	font-family: Tahoma,verdana,arial,sans-serif;
	font-size: 8pt;
	font-color: #000000;
	table-layout: fixed;
	border-width: 1px;
	border-color: #219DEC;
	border-style: solid;
	border-collapse: collapse;
	cellpadding: 0px;
   cellspacing: 0px;
   padding: 0px;
   margin: 0px;
   align: center;
}

table.gridtable1 th {
	border-width: 0px;
	border-style: solid;
	border-color: #219DEC;
	padding: 0px;
	margin: 0px;
}

table.gridtable1 td {
	border-color: #219DEC; /* AnimeRulezzz blue */
	border-style: solid;
	border-width: 0px;
	text-align: left;
	padding: 0px;
	margin: 0px;
	background-color: none;
}

.td-bluebg {background-color: #219DEC; cellspacing: 0 0 0 0; cellpadding: 0px; width: 25px; height: 25px;}
.td-description {width: 26px; height: 25px;}
.div-collapse {width: 25px; height: 25px; cellspacing: 0 0 0 0; cellpadding: 0px;}
.td-metadata {cellspacing: 0 0 0 0; cellpadding: 0px; width: 26px; height: 25px;}
.td-text {height: 25px; padding: 0px; text-align: left;}
/* table1 END */

/* POPUP onmouseover-like BEGIN. */
a.popup {
position: relative;
}

a.popup span {
display: none;
}

a.popup:hover span {
position: absolute;
top: -217px;
left: 0;
width: 248px;
height: 212px;
padding: 1px;
display: block;
border: 0px solid #FFFFFF;
}

/* Don't expect to write standards code for IE. ;) */
a.popup:hover {
  font-size: 100%;
}
/* POPUP onmouseover-like END. */

.chapter-name {
font-weight:bold;
}

/* End MAIN PART */

</style>

</head>
<body>

<!-- The following breakline tags are put only to leave enough space for the onmouseover-like CSS effect for the "?" button to be fully visible. Remove these in the final design. -->

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<!-- Table goes in the document BODY -->

<table class="gridtable1"  width="688" height= "27" cellspacing="0" cellpadding="0">
<tr>
	<td class="td-bluebg"><a href="#" class="popup"><img src="http://img838.imageshack.us/img838/1516/helpiconh.png"/><span><img src="http://img705.imageshack.us/img705/9534/aromrlegendpopup2.png" alt="Legend popup" /></span></a></td>
	<td class="td-description"><img src="http://img862.imageshack.us/img862/4259/descriptiontransparenti.png"/></td>
	<td style="width: 17px; border-left-style: none; border-right-style: none;">»</td>
	<td class="td-text" colspan="6">Naruto - volume 49 - chapter 463 (<span class="chapter-name">Sasuke vs. Raikage!!!</span>) - page 1 of 16</td>
	<td><div class="div-collapse" width="25"><img src="http://img30.imageshack.us/img30/1516/collapsen.png"/></div></td>
</tr>
</table>

</body>
</html>

如何将 MYSQL 表的选定行显示到 HTML 页面的示例表中?

【中文标题】如何将 MYSQL 表的选定行显示到 HTML 页面的示例表中?【英文标题】:How can I display the selected row of an MYSQL table into a sample table of an HTML page? 【发布时间】:2017-09-23 09:44:39 【问题描述】:

我正在尝试将 mysql db 中的选定数据行添加到 html 表中。 事实上,我可以选择数据并在控制台中显示它,但我不知道如何在 html 页面中添加它。这是我的 js 代码

var mysql = require('mysql');

var con = mysql.createConnection(
  host: "localhost",
  user: "root",
  password: "",
  database: "mydb"
);

con.connect(function(err) 
  if (err) throw err;
  //Select all customers and return the result object:
  con.query("SELECT * FROM customers", function (err, result, fields) 
    if (err) throw err;
    console.log(result);
  );
);

【问题讨论】:

【参考方案1】:

您可以使用 socket.io 将查询结果发送到客户端。然后您可以将结果添加到客户端中的 html 中。假设您的“客户”表具有以下结构:

name varchar(20)
password varchar(20)

并且您的 html 中有空元素。您可以在服务器中发出 'customers' 事件:

con.query("SELECT * FROM customers", function (err, results, fields) 
    if (err) throw err;
    console.log(result);
    // we only send results as we know the fields
    socket.emit('customers', results); 
  );

并且在客户端的代码中(pug 或jade):

script.
   let socket = io();
   socket.on('customers', data => 
       for (let i = 0, max = data.length; i < max; i++) 
           document.getElementById('customers').innerHTML += data[i].user + ' ' + data[i].password + '<br/>;
       
   );

如果您不知道表字段(几乎不可能,不是吗?)您可以同时使用查询返回的resultsfields,如下例所示:

server.js:

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const mysql = require('mysql');

let con = mysql.createPool(
    connectionLimit: 10,
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'mydb'
);


io.on('connection', function (socket) 
    console.log('client connected');

    socket.on('show', () => 
        con.query('SELECT * FROM customers', (err, results, fields) => 
            if (err) 
                throw err;
            
            //we send both: results and fields here as we don't know the fields
            socket.emit('customers', results: results, fields: fields);  
        );
    );
);

http.listen(3000, function()
    console.log('server listening on *:3000');
);

app.set('views', __dirname);
app.set('view engine', 'pug');
app.get('/', (req,res) => 
    res.render('index');
);

index.pug:

doctype html
html
head
    meta(charset="UTF-8")
    script(src="/socket.io/socket.io.js")
body
    style.
        table, th, td 
            border: 1px solid black;
            border-collapse: collapse;
        
        th, td 
            padding: 5px;
        
        #mysql 
            margin-top: 10px;
        
    div
        h3 Query results
        button(id='show') Show
    #mysql
    script.
        let socket = io();
        socket.on('customers', data => 
            let mysql = document.getElementById('mysql');
            let table = document.createElement('TABLE');
            mysql.appendChild(table);
            let tableHead = document.createElement('THEAD');
            table.appendChild(tableHead);
            let tr = document.createElement('TR');
            tableHead.appendChild(tr);
            for (let i = 0, max = data.fields.length; i < max; i++) 
                let th = document.createElement('TH');
                th.width = '75';
                th.appendChild(document.createTextNode(data.fields[i].name));
                tr.appendChild(th);
            
            let tableBody = document.createElement('TBODY');
            table.appendChild(tableBody);

            for (let i = 0, max = data.results.length; i < max; i++) 
                let tr = document.createElement('TR');
                for (let k = 0, max = data.fields.length; k < max; k++) 
                    let td = document.createElement('TD');
                    td.appendChild(document.createTextNode(data.results[i][data.fields[k].name]));
                    tr.appendChild(td);
                
                tableBody.appendChild(tr);
            
        );
        document.getElementById('show').addEventListener('click', () => 
            socket.emit('show');
        );

在这里,我们从data.fields 中检索有关表字段的信息,并将其用于构建表。所以我们只需要访问数据库并知道表的名称。

【讨论】:

【参考方案2】:

创建一个 HTTP 服务器,您可以使用节点 http 包,但是有多个框架可以让您更轻松地高效安全地完成此类任务。

我会用express.js和jade模板引擎来解释它的基本原理。 您将需要玉和表达依赖关系。所以在你的项目文件夹中: npm i express jade --save

您需要创建一个包含您的翡翠模板的views 文件夹。这是项目结构。

/node_modules
/views
    index.jade
index.js

第一个文件

// index.js file
// Create an express app
const app = require('express')();

// Create your mysql conn
const mysql = require('mysql');
const con = mysql.createConnection(
   host: "localhost",
   user: "root",
   password: "",
   database: "mydb"
);

// set view engine
app.set('view engine', 'jade');

// create a route handler, GET/
app.get('/', function (req, res) 
    // fetch your mysql data
    con.query("SELECT * FROM customers", function (err, result, fields) 
        if (err) throw err;
        // pass your data to your template file
        res.render('index', data: result);
    );
);

// open your mysql connection and start express app
con.connect(function(err) 
   if (err) throw err;
   //Select all customers and return the result object:
   app.listen(8090);
);

您的模板文件

// /views/index.jade
each d in data
  p
    = d.someproperty

这是一个非常基本的应用程序,但它会让您了解如何创建一个基本的 http 服务器、从您的服务器获取数据并显示它。

请注意,还有另一种方法,即创建一个 REST api 并将您的数据返回为 JSON 并将其显示在进行 AJAX 调用的静态网站中。

【讨论】:

以上是关于HTML HTML表的Buggy CSS(示例)的主要内容,如果未能解决你的问题,请参考以下文章

IOS 7.1 中的 UISegmentedControl Buggy Tint 颜色

通过 PHP 发送包含 CSS 样式表的 HTML 电子邮件

HTML中CSS外部样式表

HTML中CSS外部样式表

如何将 MYSQL 表的选定行显示到 HTML 页面的示例表中?

在HTML中使用CSS样式的几种方式