lendle wrote:
I have defined onclick event handler within the innerHTML property as
following:
var testButton1=oWin.document.createElement("LABEL");
testButton1.innerHTML="<input type='button' value='xx'
onclick=\"alert('123')\">";
oLabel.appendChild(testButton1);
the oLabel has already been append to document.body
You are creating invalid HTML. You are basically generating:
<label><input type='button' value='xx' onclick="alert('123')"></label>
Which makes no sense at all. A <label> can't contain an <input>. You are
then appending that mess as the child of another label (oLabel), so you
are ending up with some HTML that probably looks something like:
<label><label><input type='button' value='xx'
onclick="alert('123')"></label></label>
It appears you want to create a button and put it on document.body. So do
that. Create the button and append it to document.body, NOT to a <label>:
<script type="text/javascript">
var testButton1 = document.createElement('input');
testButton1.type = 'button';
testButton1.value = 'xx';
testButton1.onclick = function() { alert('123'); };
document.body.appendChild(testButton1);
</script>
Tested and working in IE 6.0.2800 (pre-XPSP2) and 6.0.2900 (XPSP2),
Firefox 0.9.3 and Opera 7.54.
I'm guessing you took some code you did not understand that created a
<label>, set it's innerHTML and appended the <label> to the previous
element. Now you assume that everytime you create an element, it has to
be a <label>, you have to set it's innerHTML, and you have to append it
to the previous element.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq