Javascript 为滑块上显示的每个图像创建id(基本jQuery滑块)
需要创建带有每个图像“标题”的动态标签,但是此标签不在幻灯片中。我正在使用插件:基本jQuery滑块 这样做的方法是标记:Javascript 为滑块上显示的每个图像创建id(基本jQuery滑块),javascript,jquery,dom,Javascript,Jquery,Dom,需要创建带有每个图像“标题”的动态标签,但是此标签不在幻灯片中。我正在使用插件:基本jQuery滑块 这样做的方法是标记: <p><script>document.getElementById("ID of the current image being displayed");</script></p> document.getElementById(“正在显示的当前图像的ID”) 谢谢。这应该符合您的要求。有关演示,请参见此 JavaScr
<p><script>document.getElementById("ID of the current image being displayed");</script></p>
document.getElementById(“正在显示的当前图像的ID”)
谢谢。这应该符合您的要求。有关演示,请参见此 JavaScript:
$(document).ready(function () {
function displayTitle() {
var imageTitle = $('img:visible').attr('title'); // get the title from the visible image
$('#title').html('Title: ' + imageTitle);
}
$('input:radio').bind('click', function () {
var selectedIndex = $(this).val();
$('img').hide(); // hide all images
$('img').eq(selectedIndex).show(); // show image selected by radiobutton
displayTitle();
});
displayTitle();
});
<div id="title"></div>
<input type="radio" name="display-image" value="0">display image-1
<input type="radio" name="display-image" value="1">display image-2
<input type="radio" name="display-image" value="2">display image-3
<br />
<img title="image-1" alt="image-1" />
<img title="image-2" alt="image-2" style="display:none" />
<img title="image-3" alt="image-3" style="display:none" />
HTML:
$(document).ready(function () {
function displayTitle() {
var imageTitle = $('img:visible').attr('title'); // get the title from the visible image
$('#title').html('Title: ' + imageTitle);
}
$('input:radio').bind('click', function () {
var selectedIndex = $(this).val();
$('img').hide(); // hide all images
$('img').eq(selectedIndex).show(); // show image selected by radiobutton
displayTitle();
});
displayTitle();
});
<div id="title"></div>
<input type="radio" name="display-image" value="0">display image-1
<input type="radio" name="display-image" value="1">display image-2
<input type="radio" name="display-image" value="2">display image-3
<br />
<img title="image-1" alt="image-1" />
<img title="image-2" alt="image-2" style="display:none" />
<img title="image-3" alt="image-3" style="display:none" />
显示图像-1
显示图像-2
显示图像-3
对不起,我可能遗漏了一些内容,但我不清楚这个问题。你能不能把你写的代码加进去,这样我们就可以解决问题了?你好,玛丽亚,恐怕你的问题需要更具体一些。你想要实现什么?你到底被困在哪里?再加上多一点的代码,这将是非常必要的。您知道可以使用jQuery的内置选择器吗?美元(“#youridhere”)或美元(“.yourclassehere”)或美元('p')等,因此您不需要使用普通的javascript getElementById!仅当图像可见时才会创建事件ID。