您好,其他开发人员
我是一名学生,在学校项目中使用cordova开发混合移动应用程序,遇到了需要帮助的问题。
关于我的死胡同的背景信息。
function showAvatarResult(arr) {
//if i is less than the total number of artefacts, increment by 1
for (i = 0; i < arr.length; i++) {
var avatarimage;
var avatarid;
avatarid = arr[i].avatarid;
avatarimage = "<input type='image' id='" + avatarid +"' value='" + avatarid +"' src='" + serverURL() + "/images/avatars/" + arr[i].image + "' width=17%' height='17%' />";
$("#avatar").append(avatarimage);
}
}
<form name="RegisterForm1" id="RegisterForm1">
<center>
<div id="avatar"></div>
</center>
</form>
function registerGroup() {
username = $("#newusername").val();
password = $("#newpassword").val();
email = $("#emailaddress").val();
school = $("#school").val();
contactdetails = $("#contactdetails").val();
groupname = $("#newgroupname").val();
member1 = $("#member1").val();
member2 = $("#member2").val();
member3 = $("#member3").val();
member4 = $("#member4").val();
member5 = $("#member5").val();
member6 = $("#member6").val();
member7 = $("#member7").val();
member8 = $("#member8").val();
avatarid = //stuck here
url = serverURL() + "/register.php";
var JSONObject = {
"username": username,
"password": password,
"email": email,
"school": school,
"phone": contactdetails,
"groupname": groupname,
"leader": member1,
"member2": member2,
"member3": member3,
"member4": member4,
"member5": member5,
"member6": member6,
"member7": member7,
"member8": member8,
"avatarid": //this is where I am stuck
};
$.ajax({
url: url,
type: 'GET',
data: JSONObject,
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (arr) {
_getRegisterGroupResult(arr);
}, error: function () {
validationMsg();
}
});
}
答案 0 :(得分:0)
您应为每个图像输入添加一个类,例如<input class='image-input' type='image' id=...
(在所有图像输入上应具有相同的类名),然后在单击时使用以下脚本将变量设置为等于输入的ID:< / p>
<script>
var selectedImageId;
$('.image-input').click(function(){
selectedImageId = $(this).attr('id');
});
</script>
然后,在您的registerGroup()
函数中,如下访问变量:
...
member8 = $("#member8").val();
avatarid = selectedImageId;
url = serverURL() + "/register.php";
...
...
"member8": member8,
"avatarid": avatarid
};
...
在发送AJAX请求中的数据之前,我会做一些输入验证,以确保您输入有效。