admin管理员组文章数量:1336164
this is my code :
<p onload=javascript:alert('sss')>www</p>
and the code cant alert'sss'
,
what's wrong with my code,
thanks
this is my code :
<p onload=javascript:alert('sss')>www</p>
and the code cant alert'sss'
,
what's wrong with my code,
thanks
Share Improve this question asked Feb 15, 2011 at 5:37 zjm1126zjm1126 35.7k53 gold badges125 silver badges167 bronze badges 2- need quotes around onload and javascript: is not required. – bhups Commented Feb 15, 2011 at 5:39
- 2 (An HTML validator will say what is wrong for the given doc-type). – user166390 Commented Feb 15, 2011 at 7:46
5 Answers
Reset to default 3You 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.
本文标签: htmlhow to run this javascript in the ltpgt element Stack Overflow
版权声明:本文标题:html - how to run this javascript in the <p> element- Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742344157a2457185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论