结合HTML5,CSS和JS

时间:2015-02-23 10:42:09

标签: javascript jquery css html5

我正在尝试将从codepen中提取的可编辑css表更改为稍微不同的东西。但是,我无法简单地使HTML5,CSS,JS和JQuery部分工作。这是链接:http://codepen.io/ashblue/pen/mCtuA

我已将以下代码粘贴到dreamweaver cs6中。基本上问题是,当我打开html文件时,我没有得到添加,删除,上下移动和桌面上的CSS样式。它是一个简单的HTML表,我可以在其中编辑名称,但这就是全部。我假设我只需要打开HTML文件,因为我已经链接了CSS和JS。

另外,我正在运行本地apache客户端并从本地主机打开html文件。

HTML代码为:

<!DOCTYPE html>
<html lang"en">
<head>
    <meta charset="utf-8">
    <title>...</title>
    <link rel="stylesheet" type="text/css" href="csspart.css.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <script src="jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="jspart.js.js"></script>
</head>

<body>
<div class="container">
  <h1>HTML5 Editable Table</h1>
  <p>Through the powers of <strong>contenteditable</strong> and some simple jQuery you can easily create a custom editable table. No need for a robust JavaScript library anymore these days.</p>

  <ul>
    <li>An editable table that exports a hash array. Dynamically compiles rows from headers</li> 
    <li>Simple / powerful features such as add row, remove row, move row up/down.</li>
  </ul>

  <div id="table" class="table-editable">
    <span class="table-add glyphicon glyphicon-plus"></span>
    <table class="table">
      <tr>
        <th>Name</th>
        <th>Value</th>
        <th></th>
        <th></th>
      </tr>
      <tr>
        <td contenteditable="true">Stir Fry</td>
        <td contenteditable="true">stir-fry</td>
        <td>
          <span class="table-remove glyphicon glyphicon-remove"></span>
        </td>
        <td>
          <span class="table-up glyphicon glyphicon-arrow-up"></span>
          <span class="table-down glyphicon glyphicon-arrow-down"></span>
        </td>
      </tr>
      <!-- This is our clonable table line -->
      <tr class="hide">
        <td contenteditable="true">Untitled</td>
        <td contenteditable="true">undefined</td>
        <td>
          <span class="table-remove glyphicon glyphicon-remove"></span>
        </td>
        <td>
          <span class="table-up glyphicon glyphicon-arrow-up"></span>
          <span class="table-down glyphicon glyphicon-arrow-down"></span>
        </td>
      </tr>
    </table>
  </div>
</div>
</body>
</html>

CSS代码是:

@charset "utf-8";
/* CSS Document */

.table-editable {
  position: relative;
}
.table-editable .glyphicon {
  font-size: 20px;
}

.table-remove {
  color: #700;
  cursor: pointer;
}
.table-remove:hover {
  color: #f00;
}

.table-up, .table-down {
  color: #007;
  cursor: pointer;
}
.table-up:hover, .table-down:hover {
  color: #00f;
}

.table-add {
  color: #070;
  cursor: pointer;
  position: absolute;
  top: 8px;
  right: 0;
}
.table-add:hover {
  color: #0b0;
}

JS代码是:

// JavaScript Document

var $TABLE = $('#table');
var $BTN = $('#export-btn');

$('.table-add').click(function () {
  var $clone = $TABLE.find('tr.hide').clone(true).removeClass('hide table-line');
  $TABLE.find('table').append($clone);
});

$('.table-remove').click(function () {
  $(this).parents('tr').detach();
});

$('.table-up').click(function () {
  var $row = $(this).parents('tr');
  if ($row.index() === 1) return; // Don't go above the header
  $row.prev().before($row.get(0));
});

$('.table-down').click(function () {
  var $row = $(this).parents('tr');
  $row.next().after($row.get(0));
});

// A few jQuery helpers for exporting only
jQuery.fn.pop = [].pop;
jQuery.fn.shift = [].shift;

$BTN.click(function () {
  var $rows = $TABLE.find('tr:not(:hidden)');
  var headers = [];
  var data = [];

  // Get the headers (add special header logic here)
  $($rows.shift()).find('th:not(:empty)').each(function () {
    headers.push($(this).text().toLowerCase());
  });

  // Turn all existing rows into a loopable array
  $rows.each(function () {
    var $td = $(this).find('td');
    var h = {};

    // Use the headers from earlier to name our hash keys
    headers.forEach(function (header, i) {
      h[header] = $td.eq(i).text();   
    });

    data.push(h);
  });
});

我做错了什么?

干杯:)

1 个答案:

答案 0 :(得分:0)

从您的问题来看,似乎您已经厌倦了从codepen复制代码并制作自己的HTML页面。如果是这种情况,您确定您拥有所有必需资产的副本。

在html中,预期jQuery的副本位于HTML文件的同一文件夹中。

<script src="jquery-1.11.2.min.js"></script>

另一个JS文件也可能包含不正确的文件名&#39; .js.js&#39;

<script type="text/javascript" src="jspart.js.js"></script>

要显示箭头,您需要将bootstrap glyphicons添加到项目中。 http://getbootstrap.com/components/