logo

jQueryを使用してボタンを有効/無効にするにはどうすればよいですか?

jQuery を使用してボタンを有効または無効にするには、ユーザー入力を受け入れるかどうかの機能を変更する必要があります。これは通常、「.prop()」や「.attr()」などの jQuery メソッドを通じて「disabled」プロパティまたは属性を操作することによって行われます。

jQuery を使用してボタンを有効/無効にするには、JavaScript/jQuery とともに基本的な HTML 構造が必要です。以下は、開始するための簡単なコード構造です。



HTML
     ボタン有効化/無効化title><script src= 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'>スクリプト>ヘッド> <body>  <button id='myButton'>「メボタン」をクリック><script>$(document).ready(function(){ // ボタンを有効/無効にする jQuery コード // ここにコードを追加します });  スクリプト>本文>html>>></pre> </code> <p dir='ltr'>  <br></p> <h2><span>jQueryを使用したボタンの有効化/無効化の例</span></h2><h3><span>1. .prop() メソッドの使用:</span></h3><p dir='ltr'><span>使用する</span> <span>jQueryの.prop()</span> <span>ボタンを有効/無効にするには、ボタンの「disabled」プロパティを true または false に設定する必要があり、アプリケーションの要件とユーザーの操作に基づいてボタンの対話性を効率的に制御できます。</span></p> <p dir='ltr'>  <b>  <strong>例:</strong>  </b>  <span>この例では、jQuery を使用しています。.prop() メソッドを使用して、クリックおよびダブルクリック イベントでボタンの「無効」プロパティを切り替え、スムーズなユーザー インタラクションを実現します。</span></p> <br /> <div id="container-4ae8242bd8e42d94c5c0bf390d5144e6"></div><br /><blockquote style="text-transform: capitalize;font-size: 20px; padding: 10px;"><a href="/java-string-contains">Javaに含まれる文字列</a>
</blockquote>HTML<code class='hljs'> <pre class='hljs'> <html> <head> <script src= 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'>スクリプト>ヘッド> <body> <h3>.prop() メソッドの使用h3> <button id='update'>アップデートメボタン><div style='margin-top: 50px'>  <button id='change'>meボタンをクリック> div><script>$('#change').on('click', function () { $('#update').prop( 'disabled', true ); });  $('#change').on( 'dblclick', function () { $('#update').prop( 'disabled', false ); } );  スクリプト>本文>html>>></pre> </code> <p dir='ltr'>  <b>  <strong>出力:</strong>  </b>  </p>  <img src='//techcodeview.com/img/blogathon-2021/17/how-enable-disable-button-using-jquery.webp' alt="JQueryトグル"><p>.prop() メソッドの出力例</p> <h3><span>2. .attr() メソッドの使用</span></h3><p dir='ltr'><span>を使用して、</span> <span>.attr() メソッド</span> <span>jQuery では、要素の「disabled」属性を切り替えます。ボタンをクリックすると別のボタンが無効になり、ダブルクリックすると再び有効になり、Web ページ内のユーザー操作と機能が強化されます。</span></p> <br /> <div id="container-4ae8242bd8e42d94c5c0bf390d5144e6"></div><br /> <p dir='ltr'>  <b>  <strong>例:</strong>  </b>  <span>この例では、.attr() メソッドを使用してボタンを有効/無効にしています。クリックすると別のボタンが無効になります。ダブルクリックすると再び有効になり、ユーザー操作と Web 機能が強化されます。</span></p>HTML<code class='hljs'> <pre class='hljs'> <html> <head> <script src= 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'>スクリプト>ヘッド> <body> <h3>.attr() メソッドの使用h3> <button id='update'>メボタンの更新><div style='margin-top: 50px;'>  <button id='change'>「メボタン> div>」をクリックします。<script>$('#change').on('click', function () { $('#update').attr('disabled', 'disabled'); });  $('#change').on('dblclick', function () { $('#update').removeAttr('disabled'); });  スクリプト>本文>html>>></pre> </code> <p dir='ltr'>  <b>  <strong>出力:</strong>  </b>  </p><blockquote style="text-transform: capitalize;font-size: 20px; padding: 10px;"><a href="/clustering-machine-learning">クラスタリング</a>
</blockquote> <p>  <br></p>  <img src='//techcodeview.com/img/blogathon-2021/17/how-enable-disable-button-using-jquery-2.webp' alt="JqueryToggle2"><p>.attr() メソッドの出力例</p> <p>  <br></p>  <br>  <br></article>
                         
                        </div><!--//content-->
                    </div><!--//section-inner-->                 
                </section><!--//section-->
    
            </div><!--//primary-->
            <div class="secondary col-md-4 col-sm-12 col-xs-12">
                  <aside class="info aside section">
                    <div class="section-inner">
                        <h2 class="">カテゴリ</h2>
                        <div class="content">
                            <ul class="list-unstyled">
                                <li> <a href="/hash/">ハッシュ</a> </li><li> <a href="/chemistry/">化学</a> </li><li> <a href="/time-complexity/">時間の複雑さ</a> </li><li> <a href="/powershell-tutorial/">Powershell チュートリアル</a> </li><li> <a href="/bootstrap-5-cat/">ブートストラップ 5</a> </li><li> <a href="/python-loop-programs/">Python ループ プログラム</a> </li><li> <a href="/linux-files/">Linuxファイル</a> </li><li> <a href="/floyd-warshall/">フロイド・ウォーシャル</a> </li><li> <a href="/html-dom/">Html-Dom</a> </li><li> <a href="/laws-motion/">運動の法則</a> </li>
                                
                            </ul>
                        </div><!--//content-->  
                    </div><!--//section-inner-->                 
                </aside><!--//aside-->
                
                 <aside class="testimonials aside section">
                   <div class="section-inner">
                        <h2 class="heading">混合物</h2>
                        <div class="content">
                            <div class="item">
                                 <blockquote class="quote">                                  
                                    <span> <i class="fa fa-quote-left"></i> 混合物とは、2 つ以上の異なる種類の物質から構成される物質です。混合物には、「均一混合物」と「不均一混合物」の 2 種類があります。 「混合物とは何ですか?」などの概念をさらに学びましょう。性質、例、種類、混合物と化合物の違い、よくある質問!</span>
                                </blockquote>                
                                                                                             
                            </div><!--//item-->
                            
                            <p> <a class="more-link" href="/mixtures"> <i class="fa fa-external-link"></i> 続きを読みます</a> </p> 
                            
                        </div><!--//content-->
                    </div><!--//section-inner-->
                </aside><!--//section-->
                
               
                            
                 <aside class="languages aside section">
                    <div class="section-inner">
                        <h2 class="heading">興味深い記事</h2>
                        <div class="content">
                            <ul class="list-unstyled">
                                <li class="item">
                                    <span class="title"> <strong> <a href="/negation-discrete-mathematics">離散数学における否定</a> </strong> </span>
                                    
                                </li><!--//item--><li class="item">
                                    <span class="title"> <strong> <a href="/heap-sort-data-structures">ヒープ ソート – データ構造とアルゴリズムのチュートリアル</a> </strong> </span>
                                    
                                </li><!--//item--><li class="item">
                                    <span class="title"> <strong> <a href="/drake-net-worth-2023">ドレイク純資産2023年:シャンパン・パピはどれくらいリッチ?</a> </strong> </span>
                                    
                                </li><!--//item--><li class="item">
                                    <span class="title"> <strong> <a href="/linear-time-sorting">線形時間ソート</a> </strong> </span>
                                    
                                </li><!--//item--><li class="item">
                                    <span class="title"> <strong> <a href="/sudo-command-linux-with-examples">Linux の sudo コマンドと例</a> </strong> </span>
                                    
                                </li><!--//item-->
                               
                            </ul>
                        </div><!--//content-->
                    </div><!--//section-inner-->
                </aside><!--//section-->
                
              
                 <aside class="list music aside section">
                    <div class="section-inner">
                        <h2 class="heading">人気の投稿</h2>
                        <div class="content">
                            <ul class="list"> <li><a href="/how-convert-byte-array-string-java">バイト配列から文字列Javaへ</a>
</li><li><a href="/java-string-compareto">文字列と比較する</a>
</li><li><a href="/how-get-iphone-emojis-android">AndroidでAppleの絵文字を取得する方法</a>
</li><li><a href="/quick-sort-algorithm">何か簡単な並べ替え</a>
</li><li><a href="/string-array-java">Java配列の文字列</a>
</li><li><a href="/java-enum-valueof-method">Javaの列挙型の値</a>
</li> 
                                
                                
                            </ul>
                        </div><!--//content-->
                    </div><!--//section-inner-->
                </aside><!--//section-->
              
            </div><!--//secondary-->    
        </div><!--//row-->
    </div><!--//masonry-->
    
	    <footer class="footer">
        <div class="container text-center">
                <span>
Copyright ©2025 全著作権所有 |  <a href="//techcodeview.com/">techcodeview.com</a> | <a href="/disclaimer" rel="nofollow noopener noreferrer" target="_blank">免責事項</a>  |  <a href="/about-us" rel="nofollow noopener noreferrer" target="_blank">私たちについて</a>  |  <a href="/privacy-policy" rel="nofollow noopener noreferrer" target="_blank">プライバシーポリシー</a>  </span>
        </div>
    </footer>
 
         
    <script type="text/javascript" src="https://techcodeview.com/template/assets/plugins/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="https://techcodeview.com/template/assets/plugins/bootstrap/js/bootstrap.min.js"></script>    
    

    <script type="text/javascript" src="https://techcodeview.com/template/assets/js/main.js"></script>     
	
	<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
	
</body>
</html>