SyntaxError:后面缺少名称。操作人员 基本上,我希望每次我在弹出的lightbox图像中单击类为“responsive1”的缩略图中的图像,并在顶部添加标题。 要做到这一点,我需要在函数启动后使用'this'引用该图像。一旦弹出,imgtitle类将被添加并附加到lightbox图像。 有什么想法吗?我认为我的脚本语法不正确 谢谢大家的帮助 我的网站页面与画廊,如果它可以帮助:http://www.paolobergomi.it/new-gallery/outdoor-portraits/,javascript,jquery,html,appendto,Javascript,Jquery,Html,Appendto" /> SyntaxError:后面缺少名称。操作人员 基本上,我希望每次我在弹出的lightbox图像中单击类为“responsive1”的缩略图中的图像,并在顶部添加标题。 要做到这一点,我需要在函数启动后使用'this'引用该图像。一旦弹出,imgtitle类将被添加并附加到lightbox图像。 有什么想法吗?我认为我的脚本语法不正确 谢谢大家的帮助 我的网站页面与画廊,如果它可以帮助:http://www.paolobergomi.it/new-gallery/outdoor-portraits/,javascript,jquery,html,appendto,Javascript,Jquery,Html,Appendto" />

Javascript 如何使用jquery将html附加到div中;(本)"; 我正在开发一个脚本,用于wordpress中的PHP页面。我的目的是为lightbox中我的照片库中显示的任何图像创建标题,因此我开发了以下内容: $(“.responsive1”).bind(“单击”,函数(){ $(本)。(“”)附录(“.lb nav”); }); 但不幸的是,它不起作用。我从浏览器中得到了这个反馈 >SyntaxError:后面缺少名称。操作人员 基本上,我希望每次我在弹出的lightbox图像中单击类为“responsive1”的缩略图中的图像,并在顶部添加标题。 要做到这一点,我需要在函数启动后使用'this'引用该图像。一旦弹出,imgtitle类将被添加并附加到lightbox图像。 有什么想法吗?我认为我的脚本语法不正确 谢谢大家的帮助 我的网站页面与画廊,如果它可以帮助:http://www.paolobergomi.it/new-gallery/outdoor-portraits/

Javascript 如何使用jquery将html附加到div中;(本)"; 我正在开发一个脚本,用于wordpress中的PHP页面。我的目的是为lightbox中我的照片库中显示的任何图像创建标题,因此我开发了以下内容: $(“.responsive1”).bind(“单击”,函数(){ $(本)。(“”)附录(“.lb nav”); }); 但不幸的是,它不起作用。我从浏览器中得到了这个反馈 >SyntaxError:后面缺少名称。操作人员 基本上,我希望每次我在弹出的lightbox图像中单击类为“responsive1”的缩略图中的图像,并在顶部添加标题。 要做到这一点,我需要在函数启动后使用'this'引用该图像。一旦弹出,imgtitle类将被添加并附加到lightbox图像。 有什么想法吗?我认为我的脚本语法不正确 谢谢大家的帮助 我的网站页面与画廊,如果它可以帮助:http://www.paolobergomi.it/new-gallery/outdoor-portraits/,javascript,jquery,html,appendto,Javascript,Jquery,Html,Appendto,//为了更好地理解原文,对原文进行了修改 再次感谢所有试图帮助你的人。如你所见,有一个循环。如果我像这样离开JS代码,所有图像的标题都会同时出现在每个图像上,而不是相关的标题。我无法将标题与那(这)张图片联系起来 I am developing a script to use in my PHP page in wordpress. My purpose is to create a title on any image shown in my photo gallery in lightbox

//为了更好地理解原文,对原文进行了修改 再次感谢所有试图帮助你的人。如你所见,有一个循环。如果我像这样离开JS代码,所有图像的标题都会同时出现在每个图像上,而不是相关的标题。我无法将标题与那(这)张图片联系起来

I am developing a script to use in my PHP page in wordpress. My purpose is to create a title on any image shown in my photo gallery in lightbox, so I developed this:

    $(".responsive1").bind("click", function() {
        $(this).("<div class='imgTitle'><?php echo $title ?></div>").appendTo(".lb-nav");
    });

But unfortunately it does not work. I have this feedback from the browser

>SyntaxError: missing name after . operator

Basically, I wish that every time that I click the image in the thumbnail with class `responsive1`, in the lightbox image that pop up, and a title will be added at the top.

To do this, I need to refer to that image using `this` after the function starts  the imgtitle class is added and then appended to that lightbox image, once popped up.

Any ideas? I think my script is not in the correct syntax
thanks to everyone for help

My website page with the gallery, in case it can helps: http://www.paolobergomi.it/new-gallery/outdoor-portraits/

$(“.responsive1”).bind(“单击”,函数(){
美元(“.lb nav”)。前置(“”);
});
您可以使用
append()
prepend()
并找出两者的作用:)

$(“.responsive1”).bind(“单击”,函数(){
$(“.lb nav”,此)。附加(“”);
});

我同意马克·诺尔的回答。但更详细地说,它看起来像这样

$(".responsive1").bind("click", function() {
  $(".lb-nav", this).append("<div class='imgTitle'><?php echo $title ?></div>");
});

福
巴兹

$('.foo')。在('click',function()上{
$('.my header',this.append('bar');
});
“this”定义选择器的上下文。就像在click事件发生的上下文中搜索这个选择器(.my header)


jsiddle:

在$(this)之后应该是函数名。。。不仅仅是()。。。这不是jQuery的工作方式。嗨,我试过了,但不起作用。无论如何,谢谢你。我不知道为什么。检查所有可能的缺陷。我上传了剧本谢谢Slinhart。正在尝试,但我认为我需要检查我的脚本,因为我在某个地方有缺陷。到目前为止,它还不起作用,但我正在试着看看,如果你能发布你的代码,我可以提供帮助。嗨,谢谢,我用完整的脚本修改了原始注释。不幸的是,我不明白为什么你建议的方式(这是正确的,逗号后加上“this”)它不起作用:(
$(“.responsive1”)。on(“单击”,function(){console.log($(“.lb nav”,this));$(“.lb nav”,this).prepend(“”;});
它应该是这样工作的,请检查控制台日志以确保选择了正确的元素。这是调试过程中的一个良好起点。
$(".responsive1").bind("click", function() {
  $(".lb-nav", this).append("<div class='imgTitle'><?php echo $title ?></div>");
});
<div class="foo">
    <h1 class="my-header"></h1>
    <span>foo</span>
</div>
<h2 class="my-header">baz</h2>
 $('.foo').on('click', function() {
     $('.my-header', this).append('<span>bar</span>');
});