我正在试图从数据库加载按钮状态(启用/禁用)...问题是我不知道如何访问具有此按钮的所有元素...我&# 39; m dinamically添加许多元素,每个元素包含一个图片,隐藏输入类型(保存id)和2个按钮(aprove和dissaprove)...所以如果用户按下这2个按钮中的任何一个,我应该禁用按钮和刚离开另一个启用。如果重新加载页面,它必须保存他单击的按钮....如何访问我添加的每个元素,比较和更改按钮状态?...这是我的代码:
JAVASCRIPT
function button_status(){
if (sesion != "") {
$.ajax({
url: baseurl+ 'result/buttons',
type: 'POST',
data: {
'sesion' : sesion
}
})
.done(function(data) {
$("input[type=hidden]").each(function(i,value) {
//just triying something... ANY IDEA ???
alert( $(value).closest('button').val());
});
var p = JSON.parse(data);
$.each(p, function(i, item) {
//alert(item.VOTER_ID);
});
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
}
}
ELEMENTS dinamically added
'<div class="col s6">' +
'\<div class="card medium sticky-action" id="president_'+item.POLITIC_ID+'">' +
'<div class="card-image waves-effect waves-block waves-light">' +
'<div class="video-container">' +
' <iframe src="' + baseurl + 'public/uploads/' + item.POLITIC_FILE + '" frameborder="0" allowfullscreen controls></iframe>' +
'</div>' +
'</div>' +
'<div class="card-action">' +
'<span class="card-title activator grey-text text-darken-4">' + item.POLITIC_NAME + ' ' + item.POLITIC_LASTNAME + '<i class="material-icons right">more_vert</i></span>' +
'<div class="row" style="margin-top:10px;margin-bottom:0px;">' +
'<div class="col s3">' +
'<button class=" btn waves-effect modal-trigger waves-light red darken-3 disapprove disapprove_president" data-target="verification" type="submit" name="action" ">Desapruebo</button>' +
'</div>' +
'<div class="col s3 offset-s4">' +
'<button class=" btn waves-effect modal-trigger waves-light light-green darken-3 aprove aprove_president" data-target="verification" type="submit" name="action" ">Apruebo</button>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="card-reveal">' +
'<span class="card-title grey-text text-darken-4">' + item.POLITIC_NAME + ' ' + item.POLITIC_LASTNAME + '<i class="material-icons right">close</i></span>' +
'<p>Here is some more information about this product that is only revealed once clicked on.</p>' +
'</div>' +
'</div>' +
'<input type="hidden" id="' + item.POLITIC_ID + '">' +
'</div>'