使用parse.com/Javascript和jquery。
很抱歉,如果发现帖子太长,我仍然试图了解提供的正确详细程度......
我有两个用户可以点击的图片。单击后,图像将显示在弹出框中,用户应该能够单击绿色发送按钮,图像URL将发送到parse.com后端数据库。
目前,无论您点击哪个图像,只会将john_williams.jpg图像发送到解析。
我必须做一些根本错误的事情,比如没有正确存储图像变量?
<div class="shake shake-little"><img class ="go" src="http://kudosoo.com/Pics/John_Williams.jpg" alt="img"></div>
<div class="shake shake-little"><img class ="go" src="http://kudosoo.com/Pics/Lisa_Wong.jpg" alt="img"></div>
点击后会创建一个弹出窗口,当用户点击绿色按钮时所选图像显示在“go”类中,所选图像应存储在“go”类下,以便以后可以在低于js并发送到后端数据库。
<!---Pop up box with info about the badge and options for user to complete--> <div id="modal">
<div id="heading">
Award your friend this badge!?
</div>
<div id="content">
<div id="badgeselect">
<div class= "go"></div>
</div>
<a id="send" class="button green close"><img src="images/tick.png">Yes, do it now!</a>
<a href="#" class="button red close"><img src="images/cross.png">No, Iâm insane!</a>
</div>
</div>
PARSE / JAVASCRIPT - 将网页中的图像移动到POP框中
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/jquery.reveal.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.go').css('cursor', 'pointer');
$('.go').click(function(e) { // Button which will activate our modal
$(this).width(100).height(100).appendTo('#badgeselect');
$('#modal').reveal({ // The item which will be opened with reveal
animation: 'fade', // fade, fadeAndPop, none
animationspeed: 600, // how fast animtions are
closeonbackgroundclick: true, // if you click background will modal close?
dismissmodalclass: 'close' // the class of a button or element that will close an open modal
});
return false;
});
});
</script>
<script type="text/javascript">
PARSE / JAVASCRIPT - 应该将选择的图像发送给PARSE.COM BACKEND
Parse.initialize("xxxx", "xxxx");
var badgeselected = $('.go').attr("src");
var MyBadges = Parse.Object.extend("myBadges");
var userbadges = new MyBadges();
$(document).ready(function () {
var badgeselected = $('.go').attr("src");
$("#send").click(function () {
userbadges.set("BadgeName", badgeselected);
console.log("done");
userbadges.save(null, {
success: function (results) {
// The object was saved successfully.
location.reload();
},
error: function (contact, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
alert("Error: " + error.code + " " + error.message);
}
});
});
});
</script>
答案 0 :(得分:1)
看起来你的主要问题在这里:
var badgeselected = $('.go').attr("src");
这将选择&#34; src&#34;与选择器匹配的第一个元素的attr。如果有倍数(应该至少有2个),那么你总会得到第一个。
您很可能应该向$('.go').click(function(e) {
函数添加代码以捕获正确的src,或者可能添加活动类,以便您可以在$("#send").click(function () {
函数中创建更具选择性的选择器。我只是推测,因为我不确定你的应用程序做了什么。
再看一遍,可能只需将你的行改为:
var badgeselected = $('#badgeselect .go').attr("src");