2016-10-27 29 views
0

私は以前これが動作していましたが、何らかの理由で動作が停止していました。誰でも問題を見つけることができますか?CheckBox Jquery - プロンプトが機能しない

ブラウザのソースに挿入されたhtmlとコンソールのJqueryで動作していました。しかし、JSFiddleや他のいくつかのオプションではありません。

それはチェックさ時にプロンプ​​トを表示し、チェックを外す場合は、再度プロンプトを表示する必要がありますjQueryを使って

<td class="icon"> 
      <input type="checkbox" id="my_checkbox"> 
    </td> 


    $("#my_checkbox").click(function() { 
     if (this.checked) { 
     this.checked = confirm('Are you sure you want to CONFIRM the order and EMAIL THE CUSTOMER?'); 
     }  
     else { 
     this.checked = !confirm('Do you really want to change this to NOT RECEIVED?'); 
     } 
    }); 

https://jsfiddle.net/thdbfuhs/

答えて

1
jqueryのなし

$("#my_checkbox").click(function() { 
 
    if (document.getElementById('my_checkbox').checked) { 
 
    this.checked = confirm('Are you sure you want to CONFIRM the order and EMAIL THE CUSTOMER?'); 
 
    }  
 
    else { 
 
    this.checked = !confirm('Do you really want to change this to NOT RECEIVED?'); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<td class="icon"> 
 
     <input type="checkbox" id="my_checkbox"> 
 
</td>

$("#my_checkbox").click(function(e) { 
 
    if ($(this).is(':checked')) { 
 
    this.checked = confirm('Are you sure you want to CONFIRM the order and EMAIL THE CUSTOMER?'); 
 
    
 
    }  
 
    else { 
 
    
 
    e.preventDefault(); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<td class="icon"> 
 
     <input type="checkbox" id="my_checkbox"> 
 
</td>

+0

これはうまくいきました。ボックスのチェックを外してから、無効にする方法はありますか? – me9867

+0

jqueryで自分の答えを更新しました。 – Mahi

+0

素晴らしいです、ありがとうございます。 Ticked :-) – me9867

0

あなたはJSFiddleであなたのJavaScriptの末尾にセミコロンの前に ")" を逃しました。あなたの質問に貼り付けられたJavaScriptは正しいです。

0

あなたのhtmlに最初にjquery.jsを含めてください。次に "テストされた"コードを試してください。

関連する問題