【发布时间】:2014-01-09 21:31:24
【问题描述】:
我想要做的是根据单击的按钮显示图像。到目前为止,这就是我所拥有的。我还遇到了一个叫做的东西。 http://rvera.github.io/image-picker/
我的问题是我点击了第一个按钮,出现了数据库中的第一张图片,但您无法显示任何其他图片。我还使用了 ORDER BY 函数来测试其他照片是否有效并且它们确实有效。所以它似乎卡在数据库中的第一张照片上,或者是排序后的第一张照片。
<!DOCTYPE html>
<html>
<head>
<cfquery datasource="AccessTest" name="qTest">
SELECT Account, Image, Image_ID
FROM PictureDB
</cfquery>
<script src="http://code.jquery.com/jquery-2.0.3.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").html('<img src="<cfoutput>#qTest.Image#</cfoutput>">');
});
});
</script>
</head>
<body>
<div id="div1">
<h2>
Display Image
</h2>
</div>
<cfloop query="qTest">
<button>
<cfoutput>
<tr>
<td>
#qTest.Account#
</td>
</tr>
</cfoutput>
</button>
</cfloop>
</body>
<!DOCTYPE html>
<html>
<head>
<cfquery datasource="AccessTest" name="qTest">
SELECT Account, Image, Image_ID
FROM PictureDB
</cfquery>
<script src="http://code.jquery.com/jquery-2.0.3.js">
</script>
<script>
$(document).ready(function(){
var _img = [];
<cfoutput query="qTest">
_img.push({'id': '#qTest.Image_ID#', 'src': '#qTest.Image#'});
</cfoutput>
console.log(_img);
});
$("button").on('click', function(){
var _id = $(this).data('image-id');
console.log('Image ID: ' + _id + '.');
// Find the corrosponding object in the _img array.
var result = $.grep(_img, function(e){ return e.id === _id });
// If only one is found, then reference the image src from the matching object.
if (result.length === 1) {
console.log(result[0].src);
$("#div1").html('<img src="' + result[0].src + '">');
} else {
// If none or more than one are found, show a warning.
console.warn('Could not find image ' + _id + '.');
}
});
});
</script>
</head>
<body>
<div id="div1">
<h2>
Display Image
</h2>
</div>
<cfoutput query="qTest">
<button id="account_#qTest.Image_ID#" data-image-id="#qTest.Image_ID#">
#qTest.Account#
</button>
</cfoutput>
</body>
【问题讨论】:
标签: javascript jquery html ms-access coldfusion