Home > Web Front-end > JS Tutorial > body text

JavaScript method to implement LI list data binding_javascript skills

WBOY
Release: 2016-05-16 15:47:17
Original
1325 people have browsed it

The example in this article describes how to implement LI list data binding in JavaScript. Share it with everyone for your reference. The details are as follows:

Use JavaScript to bind LI list data and obtain the corresponding LI in the list. This is a code written by an expert. After reading it, I realized that it is not very complicated. Why was the method used before so stupid?

The operation effect is as shown below:

The specific code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>JS数据绑定</title>
</head>
<body>
<ul id="list">
<li><a href="http://www.jb51.net/article/70585.htm" target="_blank">JavaScript运动减速效果实例分析</a></li>
<li><a href="http://www.jb51.net/article/70584.htm" target="_blank">JavaScript仿静态分页实现方法</a></li>
<li><a href="http://www.jb51.net/article/70583.htm" target="_blank">JavaScript实现选择框按比例拖拉缩放的方法</a></li>
<li><a href="http://www.jb51.net/article/70582.htm" target="_blank">Javascript实现可旋转的圆圈实例代码</a></li>
<li><a href="http://www.jb51.net/article/70581.htm" target="_blank">JavaScript数组各种常见用法实例分析</a></li>
</ul>
<script type="text/javascript">
  var list_obj = document.getElementById("list").getElementsByTagName("li");
  //获取list所有li对象数组
  for (var i = 0; i <= list_obj.length; i++) {
    list_obj[i].onmousemove = function() {
      this.style.backgroundColor = "#cdcdcd";
    }
    list_obj[i].onmouseout = function() {
      this.style.backgroundColor = "#FFFFFF";
    }
    list_obj[i].onclick = new function(n) {
      return function(){alert("这是第" +(n+1)+"条");}
    }(i);
  }
</script>
</body>
</html>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template