簡體   English   中英

如何使用 jquery 激活“禁用導航鏈接”?

[英]How to active the 'nav-link disabled' using jquery?

 - List item

    <ul class="nav nav-tabs-outline">
                <li class="nav-item">
                  <a class="nav-link active" data-toggle="tab" href="#shot-Title">Title</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link disabled" data-toggle="tab" href="#shot-Description" id="disco">Description</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link disabled" data-toggle="tab" href="#shot-Details">Details</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link disabled" data-toggle="tab" href="#shot-Skills">Exprtise and Skills</a>
                </li>
                  <li class="nav-item">
                  <a class="nav-link disabled" data-toggle="tab" href="#shot-Budget">Budget</a>
                </li>
              </ul>
JavaScript

 <script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

        <script type='text/javascript'>
            $(document).ready(function(){
                $('#jobpostname').keyup(function () {
                    if ($(this).val() == '') {
                        //Check to see if there is any text entered
                        // If there is no text within the input then disable the button
                        $('#disco').prop('disabled', true);

                    } else {
                        //If there is text in the input, then enable the button
                        $('#disco').prop('disabled', false);
                    }
                });
            }); 
        </script>

標題標簽中有一個輸入元素,我想做的是當我在標題輸入中輸入內容時,描述鏈接應該被激活,有沒有辦法使用 jquery 激活“禁用導航鏈接”?

Aksingh歡迎來到 Stackoverflow 的社區。

在您的代碼中disabledactive的是類而不是屬性或屬性。

所以你可以使用jQuery的addClassremoveClass方法來解決你的問題

試試這個代碼..

$(document).ready(function(){
        $('#jobpostname').keyup(function () {
            if ($(this).val() == '') {
                //Check to see if there is any text entered
                // If there is no text within the input then disable the button
                $('#disco').addClass('disabled');
                $('#disco').removeClass('active'); 

            } else {
                //If there is text in the input, then enable the button
                $('#disco').addClass('active');
                $('#disco').removeClass('disabled');
            }
        });
    }); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM