开发者

how to run this javascript in the <p> element

开发者 https://www.devze.com 2023-02-10 07:00 出处:网络
this is my code : 开发者_开发知识库<p onload=javascript:alert(\'sss\')>www</p> and the codecant alert\'sss\',

this is my code :

开发者_开发知识库<p onload=javascript:alert('sss')>www</p>

and the code cant alert'sss',

what's wrong with my code,

thanks


You can try this with body element. Because the load event is fired when the whole document is loaded; I did not find anything about element-specific load events. So I assume that element1.onload is triggered by the same event as element2.onload - the following two bodies would be equivalent:

<body>
  <p onload="javascript:alert('sss')">Text</p>
  <p onload="javascript:alert('sss')">Text</p>
</body>


<body onload="javascript:alert('sss')">
  <p>Text</p>
  <p>Text</p>
</body>

PS. that the onload event handler is now available for every HTML element in HTML5


As far as I know, onload event can only be used with body or frameset tag. You cannot use this event with p tag.

For further references, go here.


You'd be better served to move the javascript to the <body> tag:

<body onload="alert('sss');">


IIRC, onload only works reliably on the <body> element.


You should have quotes around the onload and have a semicolon.

<p onload="javascript:alert('sss');">www</p>

It should also be noticed that this is not W3C standard and the onload should really be added to the body tag.

0

精彩评论

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