使用Javascript将href文本替换为其他内容
Replacing href text with something else using Javascript
我如何替换"echo ucwords($row2[mainImage1]);"在标签的href属性与"echo $row2[selectionThumb3];"从标签的src属性使用Javascript下面?
下面是我的代码: <img class="thumbNotSelected" src="../images/ThumbSelection/<?php echo $row2[selectionThumb3]; ?>.jpg" />
<div class="mainImage magnify">
<a href="../images/MainImage/<?php echo ucwords($row2[mainImage1]); ?>.jpg" rel="lightbox" title="<?=$row2[name]?>">
<img class="mainImage small" src="../images/MainImage/<?php echo $row2[mainImage1]; ?>.jpg" /></a>
</div>
添加当前Javascript:
$('#thumbs').delegate('img', {
click: function(){
$('.mainImage').attr('src',$(this).attr('src').replace('ThumbSelection','MainImage').replace('selectionThumb','mainImage')); //here I replace the src of the Main Image to match the selected thumbnail.
var $this = $(this),
index = $this.index();
$("#thumbs img").removeClass('thumbSelected');
$this.addClass('thumbSelected');
}});
用户可以点击几个拇指。主图像在点击拇指后加载相应的图片。然而,(用于灯箱)永远不会改变以适应新加载的图片,灯箱总是使用相同的图像,而不是用户点击的那个。谢谢!
$('.mainImage a').attr('href', $('.thumbNotSelected').attr('src'));
应该做你需要的
使用下面的js,您可以动态地将链接的href更改为加载图像的相同路径。让我知道它是否有效
$('#thumbs').delegate('img', {
click: function(){
$('.mainImage').attr('src',$(this).attr('src').replace('ThumbSelection','MainImage').replace('selectionThumb','mainImage'));
$('.mainImage a').attr('href',$(this).attr('src').replace('ThumbSelection','MainImage').replace('selectionThumb','mainImage'));
var $this = $(this),
index = $this.index();
$("#thumbs img").removeClass('thumbSelected');
$this.addClass('thumbSelected');
}});
相关文章:
- 使用JavaScript将标题文本替换为按钮文本
- jQuery在用新文本替换HTML文本时淡出HTML文本,而不是仅显示
- 为什么不'使用此JavaScript将文本替换为不起作用的链接
- 将元素文本替换为子项中的值
- 使用 Jquery 将文本替换为笑脸图像
- 将页面上的文本替换为 jQuery 并提示文件下载
- 使用 JavaScript 将文本替换为图像
- 将 d3 演示中的圆圈和文本替换为包含自定义 HTML 和 ko 绑定的 foreignObject
- 在其他文本输入字段中输入文本时启用复选框
- 在HTML文本框中查找某些子字符串,然后用其他字符串替换它们
- JavaScript无法用新文本替换文本
- 将表中的文本替换为用户友好的文本
- 将.onclick属性中的文本替换为javascript
- 在包含其他标签的标签中,将一个文本替换为另一个文本
- 将文本区域中的字符串替换为其他文本
- 将某些文本中的文本替换为其他文本
- 使用Javascript将href文本替换为其他内容
- 从属性中获取数据并使用它来替换其他文本
- 如何将正则表达式{{someText}}替换为其他文本
- 用其他文本替换文本和后面的字母