English 中文(简体)
jquery: grab div Owner attr, 把它带入图像弧
原标题:jquery: grab div title attr, put it into the image src

我为建立网站Im制作一个灯塔,而我不想使用已经制作的灯塔,我想自己做。

当用户在网站上的某个位置单击, 我使用jQuery抓取该的title属性并将其插入到图像src中, 然后将该图像标签注入到.overlay_content中。

一切都起作用,除了不能抓取标题,变量不起作用,我不知道我做错了什么。它将 grabbed-img 插入图像的 src 中,而不是 span.overlay_img 的标题。

     $(document).ready(function() {
        $( .overlay_img ).click(function (){
            var docHeight = $(document).height();
            var grabbed_img = $(this).attr( title ); 

            $(".overlay_bg").height(docHeight).fadeIn(300, function(){
                $(".overlay_content").html("<img src= grabbed_img >").fadeIn(300); 
                });
            });

        });
最佳回答

你确定它没有抓取标题吗?你试过使用警报来测试吗?

警告(抓取的图像)

看起来可能是这一行有问题:

        $(".overlay_content").html("<img src= grabbed_img >").fadeIn(300); 

应:

        $(".overlay_content").html("<img src= " + grabbed_img + " >").fadeIn(300); 
问题回答

请注意:

(".overlay_content").html("<img src= " + grabbed_img + " >").fadeIn(300);

JavaScript 中不存在你尝试的这种类型的变量插值。你需要使用连接运算符来构建字符串。

它没有获取标题,因为你没有指示它获取图像的标题,你是指示它获取div的标题,而它没有。

    $( .overlay_img img )




相关问题
passing form variables into a url with php

I have the following form which allows a user to select dates/rooms for a hotel reservation. <form action="booking-form.php" method="post"> <fieldset> <div class="select-date">...

Error: "Cannot modify the return value" c#

I m using auto-implemented properties. I guess the fastest way to fix following is to declare my own backing variable? public Point Origin { get; set; } Origin.X = 10; // fails with CS1612 Error ...

C-style Variable initialization in PHP

Is there such a thing as local, private, static and public variables in PHP? If so, can you give samples of each and how their scope is demonstrated inside and outside the class and inside functions?

C#/.NET app doesn t recognize Environment Var Change (PATH)

In my C# app, I am programmatically installing an Oracle client if one is not present, which requires adding a dir to the PATH system environment variable. This all works fine, but it doesn t take ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

How to dynamically generate variables in Action Script 2.0

I have a for loop in action script which I m trying to use to dynamically create variable. Example for( i = 0 ; i &lt 3 ; i++) { var MyVar+i = i; } after this for loop runs, i would like to ...

热门标签