[英]How to make javascript created image a link
Hey there I am not very fluent with javascript and jquery. 嘿,我不太熟练使用javascript和jquery。 I want to replace a div with an image when clicked on one div and make that image clickable ie I want to add link to that image.
单击一个div时,我想用一个图像替换一个div,并使该图像可点击,即我想向该图像添加链接。
To get this I am using a javascript 为了得到这个,我正在使用JavaScript
function ReplaceContentInContainer(id,content) {
var container = document.getElementById(id);
container.innerHTML = content;
}
I am calling this javascript from my index.ctp file as 我正在从我的index.ctp文件中将此JavaScript称为
<div id="vedio-image">
</div>
<div class="title">
<a href="javascript:ReplaceContentInContainer('vedio-image',
'<img width=\'480px\' height=\'220px\' src=\'<?php echo $this->webroot.'img/'.$count['News']['videoImage']; ?> \'/ >')">
<?php echo $count['News']['title'];?>
</a>
</div>
ReplaceContentInContainer is working perfectly but I am not able to make that image clickable. ReplaceContentInContainer运行正常,但无法使该图像可单击。 Please can anyone help.
任何人都可以帮忙。
You didn't write onclick
in <img>
tag, or not surround your <img>
tag with <a>
tag 您没有在
<img>
标签中写onclick
,或者没有在<img>
标签中加上<a>
标签
Change the HTML code to : 将HTML代码更改为:
<div id="vedio-image"></div>
<div class="title">
<a href="javascript:ReplaceContentInContainer('vedio-image',
'<a href=\'http://example.com\'><img width=\'480px\' height=\'220px\' border=\'0\' src=\'<?php echo $this->webroot.'img/'.$count['News']['videoImage']; ?> \' /></a>')">
<?php echo $count['News']['title'];?></a>
</div>
sidenote: I added border="0"
to avoid a blue border appearing in IE. 旁注:我添加了
border="0"
以避免在IE中出现蓝色边框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.