var td3=document.createElement("td");
var hf=document.createElement("a");
hf.innerHTML="删除";
hf.href="javascript:;";
hf.onclick="del(this)";
td3.appendChild(hf);
The above code. After inserting the a tag into the td tag, the onclick attribute of the a tag disappears, as shown below:
Please explain what is going on?
I just tried changing the penultimate sentence to:
hf.setAttribute('onclick','del(this)');
The onclick attribute can be successfully added. . .
阿神2017-05-19 10:28:24
The first way of writing is to bind events to the hf object, and the second way of writing is to add attributes to the a tag
PHP中文网2017-05-19 10:28:24
var td3=document.createElement("td");
var hf=document.createElement("a");
hf.innerHTML="删除";
hf.href="javascript:;";
hf.onclick=del(this); =>去掉引号,并且,这个this是什么?????
td3.appendChild(hf);