Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在javascript中获取当前图像的编号_Php_Javascript_Drupal - Fatal编程技术网

Php 如何在javascript中获取当前图像的编号

Php 如何在javascript中获取当前图像的编号,php,javascript,drupal,Php,Javascript,Drupal,我正在我的站点中使用Drupal7和视图模块。并希望在我当前的缩略图上显示数字。搜索StackoverFlow并找到以下代码: HTML CODE: <img src="http://www.ambuvet.com/images/white-cat.jpg" /> <img src="http://www.biobest.co.uk/assets/images/diagnostics/cats.jpg" /> <img src="http://animal.disc

我正在我的站点中使用Drupal7和视图模块。并希望在我当前的缩略图上显示数字。搜索StackoverFlow并找到以下代码:

HTML CODE:
<img src="http://www.ambuvet.com/images/white-cat.jpg" />
<img src="http://www.biobest.co.uk/assets/images/diagnostics/cats.jpg" />
<img src="http://animal.discovery.com/guides/atoz/gallery/cat.jpg" />

JAVASCRIPT CODE:
window.onload = function() {
for (var i = 0; i < document.images.length; i++) {
    var image = document.images[i];
    image.setAttribute("index", i + "");
    image.onclick = function() {
        var index = this.getAttribute("index");
        alert("This is image #" + index);
    };
}
};
HTML代码:
JAVASCRIPT代码:
window.onload=函数(){
对于(var i=0;i
请参阅此链接:


但我不知道,如何替换当前缩略图上的get number代码。谢谢。

使用缩略图创建div作为背景图像,如

html


始终在问题本身中发布相关代码,而不仅仅是链接到它。为什么:如果你不说你的“想要”,人们会如何帮助你?你说得到这个号码是什么意思?不是索引吗?你想在缩略图上添加数字/索引吗?我有3张图片,这张图片在我的网站上是第一张,偶数,奇数。我想在我的图片上看到数字(1,2,3)。谢谢Sandeep Manne,你能在JSFIDLE上看到这段代码吗?非常感谢。这很有用,但是我有很多关于这个类的专栏,必须把这个类分开。所以,我想要第一列:image1,image2,image3。偶数列:image1、image2、image3。等
<div class="thumbnail" style="background-image: url(http://www.ambuvet.com/images/white-cat.jpg);width:100px;height:100px;"></div>
<div class="thumbnail" style="background-image: url(http://www.biobest.co.uk/assets/images/diagnostics/cats.jpg);width:100px;height:100px;"></div>
<div class="thumbnail" style="background-image: url(http://animal.discovery.com/guides/atoz/gallery/cat.jpg);width:100px;height:100px;"></div>
window.onload = function() {
    $(".thumbnail").each(function(index){
    $(this).html(index+1); // Will insert number inside div tag, use css to position it where you need
})
};​