如何使用jquery激活“已禁用导航链接”?

时间:2020-06-14 05:04:38

标签: javascript 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>

title标签中有一个input元素,我想要做的是当我在title输入中键入内容时,描述链接应该被激活, 有没有一种方法可以使用jquery激活“导航链接已禁用”?

1 个答案:

答案 0 :(得分:2)

您好 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');
            }
        });
    });