Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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/2/jquery/84.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
Javascript 由动态内容生成的jquery动态内容 (函数(){ if(typeof$(“.grid”)=“未定义”){ 返回false; }否则{ var计数=0; var images_to_place_container=“.grid”; for(图像中的变量图像到位置){ $(图像\u到\u放置\u容器); 计数++; } } })();_Javascript_Jquery_Css_Html - Fatal编程技术网

Javascript 由动态内容生成的jquery动态内容 (函数(){ if(typeof$(“.grid”)=“未定义”){ 返回false; }否则{ var计数=0; var images_to_place_container=“.grid”; for(图像中的变量图像到位置){ $(图像\u到\u放置\u容器); 计数++; } } })();

Javascript 由动态内容生成的jquery动态内容 (函数(){ if(typeof$(“.grid”)=“未定义”){ 返回false; }否则{ var计数=0; var images_to_place_container=“.grid”; for(图像中的变量图像到位置){ $(图像\u到\u放置\u容器); 计数++; } } })();,javascript,jquery,css,html,Javascript,Jquery,Css,Html,我有一个为站点动态生成图像的代码,现在我想要的是,当我悬停在其中一个元素上时,我想动态生成一个div,它的大小和位置与我悬停在上面的动态生成的对象相同。此外,所有元素都是使用CSS绝对定位的。谢谢。 (function(){ if (typeof $(".grid") === "undefined") { return false; } else { var count = 0; var images_to_place_conta

我有一个为站点动态生成图像的代码,现在我想要的是,当我悬停在其中一个元素上时,我想动态生成一个div,它的大小和位置与我悬停在上面的动态生成的对象相同。此外,所有元素都是使用CSS绝对定位的。谢谢。


(function(){ 
    if (typeof $(".grid") === "undefined") {
        return false;
    } else {
        var count = 0;
        var images_to_place_container = ".grid";
        for (var image in images_to_place) {
            $(images_to_place_container).prepend("<div class = grid-item><div class=grid-item-hover></div><a href=work.php><img src=" + images_to_place[count] + "></a></div>");
            count++;
        }
     }
})();
$(文档).ready(函数(){ //这将动态地“创建”图像。。。 $(“.container”)。追加(“”); //这将监视动态创建的元素上的单击触发器 $(.container”)。在(“单击”,“img.abc”,函数()上{ var pos_top=$(this.css(“top”); var pos_left=$(this.css(“left”); var obj=“”; $(obj).css(“顶部”,pos_顶部); $(obJ).css(“左”,位置左); $(“.container”).append(obj); }); });
为班级
abc
def
提供必要的css规则,如位置、边距等。


$(文档).ready(函数(){
//这将动态地“创建”图像。。。
$(“.container”)。追加(“”);
//这将监视动态创建的元素上的单击触发器
$(.container”)。在(“单击”,“img.abc”,函数()上{
var pos_top=$(this.css(“top”);
var pos_left=$(this.css(“left”);
var obj=“”;
$(obj).css(“顶部”,pos_顶部);
$(obJ).css(“左”,位置左);
$(“.container”).append(obj);
});
});

为类
abc
def
提供必要的css规则,如位置、边距等。

$
jQuery方法始终返回一个
对象,并且
对象从来不是一个
错误的
值。如果要检查匹配元素是否不存在,请使用
$(“.grid”).length==0
或干脆
$(“.grid”).length
。哦,我应该说什么而不是返回false?(即使代码是有效的,还有关于这个问题的提示吗?)阅读
$
方法
jQuery
总是返回一个
对象
,并且
对象
从来都不是一个
错误的值。。如果您想检查匹配的元素是否不存在,请使用
$(.grid”)。长度==0
或者干脆使用
$(“.grid”).length
。哦,我应该说什么而不是返回false?(即使代码有效,关于这个问题有什么建议吗?)
<body>
<div class='container'>
</div>
</body>
<script>
$(document).ready(function(){
    //this dynamically "creates" the images...
    $(".container").append("<img src='something.png' class='abc'>");

    //this watches for click triggers on dynamically created elements
    $(".container").on("click", "img.abc", function(){
        var pos_top = $(this).css("top");
        var pos_left = $(this).css("left");
        var obj = "<div class='def'></div>";
        $(obj).css("top", pos_top);
        $(obJ).css("left", pos_left);
        $(".container").append(obj);
    });
});
</script>