Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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
jQuery显示-默认图像_Jquery - Fatal编程技术网

jQuery显示-默认图像

jQuery显示-默认图像,jquery,Jquery,我有一个真正简单的jQueryReveal函数,它在单击链接时将图像加载到DIV中 $(function(){ jQuery(".gallery-item a").click(function(evt) { evt.preventDefault(); jQuery("#imageBox").empty().append( jQuery("<img>", { src: this.href}) ); }); }); $(函数(){ jQuery(

我有一个真正简单的jQueryReveal函数,它在单击链接时将图像加载到DIV中

$(function(){
jQuery(".gallery-item a").click(function(evt) {
    evt.preventDefault();
    jQuery("#imageBox").empty().append(
        jQuery("<img>", { src: this.href})
    );
});
});
$(函数(){
jQuery(“.gallery项a”)。单击(函数(evt){
evt.preventDefault();
jQuery(“#imageBox”).empty().append(
jQuery(“
是否有方法添加默认图像,以便加载页面时div中已有图像?

$(函数(){
$(function () {
    $(".gallery-item a").click(function (evt) {
        evt.preventDefault();
        var box = $("#imageBox").html('<img src="default.jpg" />');

        $("<img>", {src: this.href}).load(function () {
            box.empty().append(this);
        });
    });
});
$(“.gallery项目a”)。单击(功能(evt){ evt.preventDefault(); var-box=$(“#imageBox”).html(“”); $(“
$(函数)(){
$(“.gallery项目a”)。单击(功能(evt){
evt.preventDefault();
var-box=$(“#imageBox”).html(“”);
$(“试试这个:

$(function() {
    jQuery(".gallery-item a").click(function(evt) {
        jQuery("#imageBox").empty().append(
           jQuery("<img />", { src: $(this).attr("href") })
        );
        return false;
    });
});​

编辑:查看如何创建更好的对象“图像”

尝试以下操作:

$(function() {
    jQuery(".gallery-item a").click(function(evt) {
        jQuery("#imageBox").empty().append(
           jQuery("<img />", { src: $(this).attr("href") })
        );
        return false;
    });
});​


编辑:查看如何创建更好的“对象”图像"

你不能将其添加到HTML中吗?只需在页面加载时点击第一个
。你不能将其添加到HTML中吗?只需在页面加载时点击第一个
。在点击其中一个链接之前,我不会从中得到任何信息,然后默认图像会显示一秒钟,然后被替换为该链接我点击了?我没有从这一个得到任何东西,直到我点击其中一个链接,然后默认图像显示一秒钟,然后被替换为我点击的图像?使用此方法,我将把图像的url放在哪里?我会替换href吗?我假设您在标记“a”的“href”属性中有图像的url。如果您可以使用此方法替换所需内容的“href”,我会将图像的url放在哪里?我会替换href吗?我假设您的图像url位于标记“a”的“href”属性中。如果您可以替换所需内容的“href”
$(function() {
    jQuery(".gallery-item a").click(function(evt) {

         var img = new Image();
         img.src = $(this).data("urlimage");
         img.onload = function(){
             jQuery("#imageBox").empty().append(img);
         };

        return false;
    });
});​