Js simply implements exchanging the values of Li

  • 2020-03-30 03:04:41
  • OfStack

Hand over the value of li. HTML
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
<title> exchange Li The value of the </title> 
<script type="text/javascript"> 
window.onload= function() { 
var lis = document.getElementById("ulList").childNodes; 

for (var i = 0; i < lis.length; i++) { 
var myli = lis[i]; 
//Determine if it's a label
if (myli.nodeType == 1) { 
//Switch places with one of the li's down here
myli.onclick = function() { 
if (this.nextElementSibling) { 
var nextli = this.nextElementSibling;//I can only use this, not myli
document.getElementById("ulList").insertBefore(nextli, this); 

<ul id="ulList"> 
<li> Beijing </li> 
<li> shanxi </li> 
<li> Shanghai </li> 
<li> tianjin </li> 
<li> henan </li> 

Related articles: