所以我有一个使用 json2html 的代码块模板
var template = {'<>':'div','class':'col-lg-12 col-md-24 col-sm-24 col-xs-24','html':[
{'<>':'div','class':'product col-lg-offset-1 col-lg-22 col-md-offset-0 col-md-24 col-sm-offset-0 col-sm-24 col-xs-offset-0 col-xs-24','html':[
{'<>':'div','class':'prodimg col-lg-8 col-md-8 col-sm-8 col-xs-8','html':[
{'<>':'img','src':'${source}','alt':'${name}', 'class':'img-responsive'}
]},
{'<>':'div','class':'prodetails col-lg-16 col-md-16 col-sm-16 col-xs-16','html':[
{'<>':'span','class':'prodname','html':'${name}'},
{'<>':'div','class':'mT20','html':[
{'<>':'p','html':'${info1}'},
{'<>':'p','html':'${info2}'},
{'<>':'p','html':'${info3}'}
]}
]}
]}
]};
粗体部分是我要运行函数 showPic(img); 的图像。其中“img”是模板的第 4 行。
具有“产品”类的 div 是我希望用户单击的内容,它以 img 为目标并将 img 发送到 showPic。
我希望它使用 jQuery 来定位 .product 。
这是目前的代码。 http://ttrltest.000webhostapp.com/tbcl-products.html
我在回复的帮助下尝试 编辑:
$('.product').click(function(){
showPic($(this).find('img'));
});
而且我无法从图像元素中获取 src 属性。