2017-10-07 31 views
-1

特定の条件が発生した場合に無効になるボタンがあります。 Order_statusがの場合はとなり、Acceptのボタンは無効になります。 order_statusがPendingのときは他のボタンと同じですが、Sendボタンは無効です。それをどうすれば実現できますか?jqueryを使用して無効/有効にするボタン

ASDのボタンを無効にすることはできますが、#asdを#submitAcceptに変更すると、[同意する]ボタンは無効になりませんでした。

しかし、今のところ、order_statusがAcceptされたときの達成方法を教えてください。Acceptボタンは無効です。私はあなたが私のprobと私を助けることができることを願って、私は何をすべきかわからない。本当にあなたからの助けを感謝します、ありがとう!

私のコードは今です。

function viewOrder(order_id, order_id, user_id, order_date, order_time, order_deliveryCharge, order_totalAmount, address, coordinates, driver_number, order_status) { 
 
    
 
    document.getElementById("t_order_id").setAttribute("value", order_id); 
 
    document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id); 
 
    document.getElementById("t_user_id").setAttribute("value", user_id); 
 
    document.getElementById("t_order_date").setAttribute("value", order_date); 
 
    document.getElementById("t_order_time").setAttribute("value", order_time); 
 
    document.getElementById("t_order_deliveryCharge").setAttribute("value", order_deliveryCharge); 
 
    document.getElementById("t_order_totalAmount").setAttribute("value", order_totalAmount); 
 
    document.getElementById("t_address").setAttribute("value", address); 
 
    document.getElementById("t_coordinates").setAttribute("value", coordinates); 
 
    document.getElementById("t_drivers_number").setAttribute("value", driver_number); 
 
    document.getElementById("t_order_status").setAttribute("value", order_status); 
 
    document.getElementById("ORDER_MODAL_ACCEPT").setAttribute("value", order_id); 
 
    document.getElementById("ORDER_MODAL_DELIVER").setAttribute("value", order_id); 
 
    document.getElementById("ORDER_MODAL_CANCEL").setAttribute("value", order_id); 
 
    
 
    
 
    $(document).on("click", "#asd", function() { // MY JQUERY 
 
     if ($("#t_order_status").val() == "Accepted") { 
 
       $("#asd").prop("disabled", true); 
 
     } 
 
    }); 
 
    
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
<div class="form-group"> 
 
    <label for="order_status" class="col-sm-2 control-label" style="width:20%;">Order Status</label> 
 
    <input type="text" class="form-control" name="order_status" id="t_order_status" style="width:80%;" placeholder="" value="" required="required" readonly> 
 
    </div> 
 
    
 
    <button type="button" input style="background-color:#4CAF50;color:white;border-color:#000000;" name="submitDelivered" id="submitDelivered" class="btn btn-success" data-toggle="modal" data-target="#myDeliverModal" onclick="deliver('<?= $_POST['order_id'] ?>')" > Delivered </button> 
 
    <button type="button" input style="background-color:#0000FF;color:white;border-color:#000000;" name="submitAccept" id="submitAccept" class="btn btn-success" data-toggle="modal" data-target="#myAcceptModal" onclick="accept('<?= $_POST['order_id'] ?>')" > Accept </button> 
 
    <button type="button" style="background-color:#FFFF00;color:black;border-color:#000000;" class="btn btn-success" data-toggle="modal" data-target="#myDropdown" onclick="send('<?= $_POST['order_id'] ?>')"> Send </button> 
 
    <button type="button" input style="background-color:#f44336;color:white;border-color:#000000;" name="submitCancel" id="submitCancel" class="btn btn-success" data-toggle="modal" data-target="#myCancelModal" onclick="cancel('<?= $_POST['order_id'] ?>')">Cancel</button> 
 
    <button type="button" name="asd" id="asd" class="btn btn-primary" onclick="asd"> ASD </button>

+0

*「#asdを#submitAcceptに変更すると、[Accept]ボタンが無効になりませんでした」* - 動作しないコードを表示するために質問をしてください。 '。on(" click ")'コードが 'viewOrder()'関数の中にあるのはなぜですか?さて、 '.value = order_id'というだけで、' .setAttribute( "value"、order_id) 'を使って要素の値を設定しないでください。 – nnnnnn

+0

@nnnnnn Cuzボタンを無効にするには、まずviewOrderをクリックする必要があります。 – Dragon12

答えて

0

.disabledメソッドを使用してtrueに設定します。

window.onload = function() { 
    if(document.getElementById("t_order_status").value == "Accepted") { 
     document.getElementById("asd").disabled = true; 
    } 
} 
+1

* ".disabledメソッドを使用する" * - これはメソッドではなく、プロパティです。しかし、とにかく、なぜOPのjQueryは同じことをしないでしょうか?クリックハンドラから 'window.onload'ハンドラに変更したのはなぜですか? – nnnnnn

関連する問題