if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
but i use attachEvent like this,it work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var text = document.createElement("span");
text.innerHTML="<-click this";
var div = documet.createElement("div");
div.appendChild(img); //can work
div.appendChild(text); 6 2297
On Apr 26, 7:13 pm, SkyZhao <sky.zhao....@gmail.comwrote:
if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
but i use attachEvent like this,it work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var text = document.createElement("span");
text.innerHTML="<-click this";
var div = documet.createElement("div");
div.appendChild(img); //can work
div.appendChild(text);
Was there a problem with the answer I supplied before?
<URL: http://groups.google.com/group/comp.lang.javascript/msg/de4303743575ead4>
Peter
On 4月27日, 上午10时29分, Peter Michaux <petermich....@gmail.comwrote:
On Apr 26, 7:13 pm, SkyZhao <sky.zhao....@gmail.comwrote:
if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
but i use attachEvent like this,it work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var text = document.createElement("span");
text.innerHTML="<-click this";
var div = documet.createElement("div");
div.appendChild(img); //can work
div.appendChild(text);
Was there a problem with the answer I supplied before?
<URL:http://groups.google.com/group/comp.lang.javascript/msg/de4303743575ead4>
Peter
thx;
but it also can't work like this;
img.attachEvent("onclick",function(){alert("test") });
when i use the attachEvent and use innerHTML . the event can't work;
On Apr 26, 7:13 pm, SkyZhao <sky.zhao....@gmail.comwrote:
if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
The above line removes the image from the div. InnerHTML removes all
other children from the element.
replace this
div.innerHTML="<-click this";
with
div.appendChild(document.createTextNode('<--click this'));
You should be able to see both the image and the text this way.
Peter
On 4月27日, 上午11时15分, Peter Michaux <petermich....@gmail.comwrote:
On Apr 26, 7:13 pm, SkyZhao <sky.zhao....@gmail.comwrote:
if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
The above line removes the image from the div. InnerHTML removes all
other children from the element.
replace this
div.innerHTML="<-click this";
with
div.appendChild(document.createTextNode('<--click this'));
You should be able to see both the image and the text this way.
Peter
can i use this
div.innerHTML+="<--click this" ?
On Apr 26, 8:18 pm, SkyZhao <sky.zhao....@gmail.comwrote:
On 4鏈27鏃, 涓婂崍11鏃15鍒, PeterMichaux <petermich...@gmail.comwrote:
On Apr 26, 7:13 pm, SkyZhao <sky.zhao....@gmail.comwrote:
if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
The above line removes the image from the div. InnerHTML removes all
other children from the element.
replace this
div.innerHTML="<-click this";
with
div.appendChild(document.createTextNode('<--click this'));
You should be able to see both the image and the text this way.
Peter
can i use this
div.innerHTML+="<--click this" ?
You can but I probably wouldn't since this requires conversion of dom
to string and back to dom for the image. That is unnecessary.
Peter
SkyZhao said the following on 4/26/2007 11:18 PM:
On 4鏈27鏃, 涓婂崍11鏃15鍒, Peter Michaux <petermich...@gmail.comwrote:
>On Apr 26, 7:13 pm, SkyZhao <sky.zhao....@gmail.comwrote:
>>if i use AttachEvent like this,it can't work; eg: var img = document.createElement("img"); img.attachEvent("onclick",alert("test")); var div = document.createElement("div"); div.appendChild(img); //can't work; div.innerHTML="<-click this";
The above line removes the image from the div. InnerHTML removes all other children from the element.
replace this
>>div.innerHTML="<-click this";
with
div.appendChild(document.createTextNode('<--click this'));
You should be able to see both the image and the text this way.
Peter
can i use this
div.innerHTML+="<--click this" ?
Did you try it? Or are you just guessing wanting someone to do it for you?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John McCarthy |
last post by:
Novice here - using notepad only .....
function MenuBarIn(E)
{
var i;
with (document.getElementById(E.id))
{
|
by: PedroVasconcelos |
last post by:
Hello everyone!
I am trying to copy AttachEvents but i don't know how.
Because innerHTML doesn't copy the AttachEvents.
Here is an example:
<script>
function a(){
alert("is changing");
}...
|
by: Adrian Parker |
last post by:
Using asp.net 2003
When I use
document.attachEvent("onmousemove", resetTimer);
The first time into a page, it works fine, but the 2nd time the page is
loaded (not postback) it gives a...
|
by: Bert |
last post by:
Hello,
I'm having some problems with creating a script that works on both
Mozilla browsers as IE.
I want to change the background color of textareas and input text
fields as soon as somebody...
|
by: luco |
last post by:
Hi!
I'm having a problem with attachEvent function. I'd like to add
attachEvent dynamically to some objects so that each could execute
event function with different parameter value. The question...
| |
by: J |
last post by:
I am having problems dynamically adding more than one event handler to
an input. I have tried the Javascript included at the bottom. The
lines
inp.attachEvent('onkeyup',...
|
by: SkyZhao |
last post by:
i use attachEvent to bind a event ;
code:
img.attachEvent("onclick",alert("aa"));
div.appendChild(img);
div.innerHTML+="some text";
the event can not work; why can't i use it?
if i use...
|
by: dwmartin18 |
last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |