我遇到以下问题:我需要在类“ estadoEntregado”的“ no”中具有属性“ entrega”时,禁用注释按钮。
我试图以与Jquery共享的方式来解决它,但是它不起作用。
我将状态段的html代码和按钮段的下面放在同一文件中,但是我不想让代码这么长,而只放置与问题相关的内容
HTML
if($value1["envio"] == 0){
echo '<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar" style="width:33.33%">
<i class="fa fa-check"></i> Aceptado
</div>
<div class="progress-bar progress-bar-default" role="progressbar" style="width:33.33%">
<i class="fa fa-clock-o"></i> Enviando
</div>
<div class="progress-bar progress-bar-success" role="progressbar" style="width:33.33%">
<i class="fa fa-clock-o estadoEntregado" entrega="no"></i> Entregado
</div>
</div>';
}
if($value1["envio"] == 1){
echo '<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar" style="width:33.33%">
<i class="fa fa-check"></i> Aceptado
</div>
<div class="progress-bar progress-bar-default" role="progressbar" style="width:33.33%">
<i class="fa fa-check"></i> Enviando
</div>
<div class="progress-bar progress-bar-success" role="progressbar" style="width:33.33%">
<i class="fa fa-clock-o estadoEntregado" entrega="no"></i> Entregado
</div>
</div>';
}
if($value1["envio"] == 2){
echo '<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar" style="width:33.33%">
<i class="fa fa-check"></i> Aceptado
</div>
<div class="progress-bar progress-bar-default" role="progressbar" style="width:33.33%">
<i class="fa fa-check"></i> Enviando
</div>
<div class="progress-bar progress-bar-success" role="progressbar" style="width:33.33%">
<i class="fa fa-check estadoEntregado" entrega="si"></i> Entregado
</div>
</div>';
}
按钮部分:
<a class="calificarProducto" href="#modalComentarios" data-toggle="modal" idComentario="'.$comentarios["id"].'">
<button class="btn btn-default backColor" id="botonComentarios">Calificar Producto</button>
</a>
jQuery:
var attr = $('.estadoEntregado').attr('entrega');
// For some browsers, `attr` is undefined; for others,
// `attr` is false. Check for both.
if (attr == "no") {
$('#botonComentarios').attr("disabled", true);
}
答案 0 :(得分:2)
您正在使用哪个版本的jQuery?您可以在设置.prop
.attr
代替disabled
这就是它的外观:
var attr = $('.estadoEntregado').attr('entrega');
if (attr === "no") {
$('#botonComentarios').prop("disabled", true);
}
在此处阅读更多信息:http://api.jquery.com/prop/