Original Eco-JS, mouse down, after the simple example of those cells _javascript skills

Source: Internet
Author: User

The original is to determine those cells were selected, the results found not workable, only to judge the mouse down after those cells

The reason for this is that there are many interesting places in the case.

ONMOUSEOVER constant triggering, resulting in a lot of repeating elements

Because the event is bound to the entire table, there are also undefined

The repeated entry and exit of the mouse will result in intermittent repetition of the same elements,

How to solve them!

<table border= "1" id= "DNF" > 
  <tr> 
     
     
    <td rowspan= "2" >2</td> 
    <td>2</td > 
    <td>4</td> 
  </tr> 
  <tr> 
     
     
    <td>2</td> 
    <td>4< /TD> 
  </tr> 
Window.onload = function () {var flag = false;<br>//When mouse is pressed, true, release is true var indexs =[];<br> 
    The cell used to hold the mouse over is the position of the entire table, is initialized when the mouse is pressed, Dnf.onmousedown = function () {flag = true; 
  Indexs = []; Dnf.onmousemove = function (e) {if (flag)//If the mouse is pressed, the composite code {Indexs.push is executed (e.target,dnf.get 
    Elementsbytagname ("TD"))} Dnf.onmouseup = function () {flag = false; 
  Deleteundefined (); The null element Deleterepaint () is present because it passes through a border;//Because onmouseover does not trigger only once, and we choose to be able to iterate through one cell alert (INDEXS); function Deleterepaint () {for (Var j=0;j<indexs.length;j++)/Guaranteed The J element is unique {var head = Index 
      S[J]; for (var i=j+1;i<indexs.length;i++)//deletes and J duplicates {if (head = = Indexs[i]) {Indexs.spli 
          CE (i,1); 
        i--; function deleteundefined () {for (Var i=0;i<indexs.length;i++) {if ( typeof inDexs[i] = = "undefined") {Indexs.splice (i,1); 
      i--; 
     
    }} function Search (a,a) {var length = A.length; 
      for (Var i=0;i<length;i++) {if (a = = A[i]) {return i; {}}}} </script>

Above this original eco-JS, mouse down, after the simple example of those cells are small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.