Today do dongdong time to use JS to create HTML elements and then dynamically add methods to the element, walked a lot of detours. Finally, the solution to release, so that everyone after less detours.
JS file
function Checknull (ID)
{
DoSomething
}
var checknewnull= function (ID)
{
return function () {
Checknull (ID);
}
}
Adding methods to HTML elements
Create a TEXTAREA
Std2area=document.createelement ("textarea");
Setting properties
Std2area.setattribute ("id", "member_task" +position);
Std2area.setattribute ("name", "Member_task" +position);
Add method
Std2area.attachevent ("onblur", Checknewnull ("Member_task" +position));
If the Add method is written as: Std2area.attachevent ("onblur", Checknull ("Member_task" +position));
or written std2area.attachevent ("onblur", checknull);
Then there will be an error. The reason for this is to assign the return value of Checknull ("Member_task" +position) to onblur
Instead of assigning the function checknull to the element. So the right thing to do is to return checknull with a function, as shown above.
Other ways to write the final Add method:
Std2area.onblur=checknull;
Std2area.setattribute ("onblur", checknull);