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>
标题标签中有一个输入元素,我想做的是当我在标题输入中输入内容时,描述链接应该被激活,有没有办法使用 jquery 激活“禁用导航链接”?
解决方案
嗨Aksingh欢迎来到 Stackoverflow 的社区。
在您的代码中disabled
,并且active
是类而不是属性或属性。
所以你可以使用jQuery的addClass
和removeClass
方法来解决你的问题
试试这个代码..
$(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');
}
});
});
推荐阅读
- stm32 - stm32 spi 在上升沿写入并在下降沿读取,可能吗?
- android - 停止媒体播放器后Android再次播放不炒锅
- php - 无法回显来自 MYSQL 数据库的数据
- ruby-on-rails - 生成要使用的订单号而不是 ID
- matlab - 如何使用编辑工具在 MATLAB R2014a 中旋转 X 标签?
- javascript - XMLHttpRequest中responseText的限制
- reactjs - 如何在 ReactJs 中的 onClick 事件上回调函数
- asp.net-mvc - 所有项目文件显示为杂项文件。视觉工作室 2017
- influxdb - 将 influxdb 数据建模为标签和字段
- swift - didSelectRowAtIndexPath 遇到问题