can not add onmousemove

时间:2017-06-09 12:56:49

标签: javascript html css3

I have next table:

div class="container">
    <table id="myTable">
    <tr onmousemove="changeVposition(this)">
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
    </tr>
    <tr onmousemove="changeVposition(this)">
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
    </tr>
    <tr onmousemove="changeVposition(this)">
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
    </tr>
    <tr onmousemove="changeVposition(this)">
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
      <td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
    </tr>

    </table>
    <button onclick="appendCol()" id ="appendCol"></button>
    <button onclick="appendRow()" id ="appendRow"></button>
    <button onclick="deleteRow()" id="deleteRow"></button>
    <button onclick="deleteCol()" id="deleteCol"></button> 

  </div>

and during creating new column with function

function appendCol() {
      var tbl = document.getElementById("myTable")
      var tr = tbl.getElementsByTagName("tr");
      for (i = 0; i < tr.length; i++) {

        var td = document.createElement('td');
        td.onmousemove = changeGposition(this);
        var div = document.createElement('div')
        div.className = "cell"
        tr[i].appendChild(td).appendChild(div)



      }

but it does not work, onmousemove was not added

Who have any idea why it is not work?

Note: with <div> element it is working and I have next DOM after function was called

<td onmousemove="changeGposition(this)">
        <div class="cell"></div>
      </td>
<td>
        <div class="cell"></div>
      </td>

1 个答案:

答案 0 :(得分:2)

当你这样做时

var x = document.cookie;

调用函数并将其返回的内容分配给事件监听器。

应该是

x = x.substr(x.indexOf('sideBar'));