开发者

how to insert this javascript in php

how to insert this javascript code :

thejavascript

<A HREF="javascript:void(0)" onclick="window.open('welcome.html','welcome')"> </A>

inside img src in php

<img src="http:'.$iv[$j].'.jpg" height="220" width="200"  alt="Image '.ucwords($kw).'"开发者_开发知识库 "thejavascript">

Thanks


You can use this jQuery script to add and onClick event in your balise img but you must adding an attribute id into your image. An id must be unique in your html page.

$("img#idImage").click(function({
    window.open('welcome.html','welcome');
}));

$kw = $ucwords($kw);
"<img id='idImage' src='http:{$iv[$j]}.jpg' height='220' width='200' alt='Image {$kw}' />";

But the best will be to separate attributes height and width into a CSS stylesheet.


Insert the following HTML outside PHP brackets and it should work according to the way you posted it. I'm making a few assumptions, one being that the link you posted wraps the image code and that the PHP variables turn the image into valid code.

<a href="javascript:void(0);" onclick="window.open('welcome.html','welcome')">
    <img src="http:<?=$iv[$j]; ?>.jpg" height="220" width="200"  alt="Image <?=ucwords($kw); ?>">
</a>


More simple, replace "thejavascript" (with the "") by :

onclick="window.open(\'welcome.html\',\'welcome\')"


A bit different approach, onclick event is on img tag.

$javascript="window.open('welcome.html','welcome')";

$img='<img src="http:'.$iv[$j].'.jpg" height="220" width="200"  onclick="'.$javascript.'">';

echo $img;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜