开发者

my image not responding for click function...why?

开发者 https://www.devze.com 2023-02-08 08:19 出处:网络
var cell3 = row.insertCell(2); var element3 = document.createElement(\"img\"); el开发者_StackOverflowement3.setAttribute(\"src\",\"img/delete.png\");
var cell3 = row.insertCell(2);
var element3 = document.createElement("img");
el开发者_StackOverflowement3.setAttribute("src","img/delete.png");
//  element3.setAttribute("id",f);
cell3.appendChild(element3);
document.forms[0].element3.addEventListener("click",deleteRow('dataTable'),false);


Image is not a form element. Try this instead:

element3.addEventListener("click", function() { deleteRow('dataTable'); }, false);


Or perhaps this can help? I wrote it just now to check for my own information if the image elements would be added to the form when adding them to cells in a table in a form.

window.onload = function() {
  var form = document.getElementsByTagName('form')[0];
  form.action = "http://google.com/search";
  var hiddenField = document.createElement('input');
  hiddenField.type = "hidden";
  hiddenField.name = "q";
  hiddenField.id = "q";
  form.appendChild(hiddenField);
  var table = document.getElementsByTagName('table')[0];
  for (var i = 0; i < table.rows.length; i++) {
    table.rows[i].onmouseover = function() {
      document.getElementById("q").value = this.cells[0].innerHTML
    }
    table.rows[i].cells[0].appendChild(document.createTextNode('Row ' + (i + 1)));
    var submitImage = document.createElement('input');
    submitImage.type = "image";
    submitImage.src = "http://www.softicons.com/download/system-icons/pleasant-icons-by-harwen-zhang/png/48/Search.png";
    table.rows[i].cells[1].appendChild(submitImage);
  }
}
<form>
  <table>
    <tr>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
    </tr>
  </table>
</form>

0

精彩评论

暂无评论...
验证码 换一张
取 消