list.js javascript库无法正常工作

时间:2014-01-16 15:35:25

标签: html sorting javascript

我期待使用list.js by Jonny。在这里,在我的示例中,我尝试使用与给定here相同的列表代码。我在我的代码文件中复制了HTML,CSS和JS部分。此外,我下载并保存了给定的list.js并将其粘贴到与我的代码文件相同的目录中。我正在使用WAMP,当我打开页面时,搜索功能无法在线工作。当我单击sort by name按钮时,表格不会动态更新,甚至不会更新。

有人可以告诉可能是什么问题吗?谢谢:))

<!DOCTYPE html>
<html>
<head>
<script src="list.js"></script><meta charset=utf-8 />
<title>Existing list</title>
</head>
<body>
<script>
var options = {
  valueNames: [ 'name', 'born' ]
};

var userList = new List('users', options);
</script>
<style>
.list {
  font-family:sans-serif;
  margin:0;
  padding:20px 0 0;
}
.list > li {
  display:block;
  background-color: #eee;
  padding:10px;
  box-shadow: inset 0 1px 0 #fff;
}
.avatar {
  max-width: 150px;
}
img {
  max-width: 100%;
}
h3 {
  font-size: 16px;
  margin:0 0 0.3rem;
  font-weight: normal;
  font-weight:bold;
}
p {
  margin:0;
}

input {
  border:solid 1px #ccc;
  border-radius: 5px;
  padding:7px 14px;
  margin-bottom:10px
}
input:focus {
  outline:none;
  border-color:#aaa;
}
.sort {
  padding:8px 30px;
  border-radius: 6px;
  border:none;
  display:inline-block;
  color:#fff;
  text-decoration: none;
  background-color: #28a8e0;
  height:30px;
}
.sort:hover {
  text-decoration: none;
  background-color:#1b8aba;
}
.sort:focus {
  outline:none;
}
.sort:after {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid transparent;
  content:"";
  position: relative;
  top:-10px;
  right:-5px;
}
.sort.asc:after {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #fff;
  content:"";
  position: relative;
  top:13px;
  right:-5px;
}
.sort.desc:after {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid #fff;
  content:"";
  position: relative;
  top:-10px;
  right:-5px;
}
</style>
  <div id="users">
    <input class="search" placeholder="Search" />
    <button class="sort" data-sort="name">
      Sort by name
    </button>

    <ul class="list">
      <li>
        <h3 class="name">Jonny Stromberg</h3>
        <p class="born">1986</p>
      </li>
      <li>
        <h3 class="name">Jonas Arnklint</h3>
        <p class="born">1985</p>
      </li>
      <li>
        <h3 class="name">Martina Elm</h3>
        <p class="born">1986</p>
      </li>
      <li>
        <h3 class="name">Gustaf Lindqvist</h3>
        <p class="born">1983</p>
      </li>
    </ul>

  </div>
</body>
</html>

1 个答案:

答案 0 :(得分:7)

Javascript

  <script>
    var options = {
      valueNames: [ 'name', 'born' ]
    };

    var userList = new List('users', options);
  </script>

需要放置在HTML下方(在结束正文标记之前),因为script需要在html之后运行。目前,script上面有html - 因此它不知道标记是否存在。