如何禁用输入字段,但不禁用单击的输入字段,然后启用所有输入字段
How to disable input fields but not the clicked one and then enable all
我的项目中有一些按钮,如果单击一个按钮而不是单击的按钮,我想禁用所有按钮。当我再次单击该按钮时,我想启用所有这些按钮。这是我尝试过的,但没有奏效:
$('#TOSTORAGE').click(function(){
$('#TOULD').prop('disabled', true'false);
$('#TOTRAIN').prop('disabled', true'false);
$('#TOARRIVAL').prop('disabled', true'false);
$('#TOHANDLER').prop('disabled', true'false);
});
$('#TOULD').click(function(){
$('#TOSTORAGE').prop('disabled', true'false);
$('#TOTRAIN').prop('disabled', true'false);
$('#TOARRIVAL').prop('disabled', true'false);
$('#TOHANDLER').prop('disabled', true'false);
});
$('#TOTRAIN').click(function(){
$('#TOSTORAGE').prop('disabled', true'false);
$('#TOULD').prop('disabled', true'false);
$('#TOARRIVAL').prop('disabled', true'false);
$('#TOHANDLER').prop('disabled', true'false);
});
$('#TOARRIVAL').click(function(){
$('#TOSTORAGE').prop('disabled', true'false);
$('#TOULD').prop('disabled', true'false);
$('#TOTRAIN').prop('disabled', true'false);
$('#TOHANDLER').prop('disabled', true'false);
});
$('#TOHANDLER').click(function(){
$('#TOSTORAGE').prop('disabled', true'false);
$('#TOULD').prop('disabled', true'false);
$('#TOTRAIN').prop('disabled', true'false);
$('#TOARRIVAL').prop('disabled', true'false);
});
.btn-hl2{
color:#ffffff;
height:90px;
width: 340px;
display: inline-block;
margin: 6px;
text-align: center;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
background-color: #536e7f;
border: 1px solid #ffffff;
white-space: nowrap;
padding: 4px 10px;
font-size: 34px;
font-family: inherit;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
font:#FFF;
}
.btn-hl3{
color:#ffffff;
height:90px;
width: 695px;
display: inline-block;
margin: 6px;
text-align: center;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
background-color: #536e7f;
border: 1px solid #ffffff;
white-space: nowrap;
padding: 4px 10px;
font-size: 34px;
font-family: inherit;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
font:#FFF;
}
.btn-hl2:hover {
background-color: #e4b527;
}
.btn-hl3:hover {
background-color: #e4b527;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="TOSTORAGE" type="submit" class="btn-hl2" name="TOSTORAGE">
<span aria-hidden="true"></span> TO STORAGE
</button>
<button id="TOULD" type="submit" class="btn-hl2" name="TOULD">
<span aria-hidden="true"></span> TO ULD
</button>
<button id="TOTRAIN" type="submit" class="btn-hl2" name="TOTRAIN">
<span aria-hidden="true"></span> TO TRAIN
</button>
<button id="TOARRIVAL" type="submit" class="btn-hl2" name="TOARRIVAL">
<span aria-hidden="true"></span> TO ARRIVAL
</button>
<button id="TOHANDLER" type="submit" class="btn-hl3" name="TOHANDLER">
<span aria-hidden="true"></span> TO HANDLER
</button>
您可以通过以下方式设置公共类名并实现:
$('.btn-common').click(function(){
$('.btn-common').prop('disabled', true);
$(this).prop('disabled', false);
});
.btn-hl2{
color:#ffffff;
height:90px;
width: 340px;
display: inline-block;
margin: 6px;
text-align: center;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
background-color: #536e7f;
border: 1px solid #ffffff;
white-space: nowrap;
padding: 4px 10px;
font-size: 34px;
font-family: inherit;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
font:#FFF;
}
.btn-hl3{
color:#ffffff;
height:90px;
width: 695px;
display: inline-block;
margin: 6px;
text-align: center;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
background-color: #536e7f;
border: 1px solid #ffffff;
white-space: nowrap;
padding: 4px 10px;
font-size: 34px;
font-family: inherit;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
font:#FFF;
}
.btn-common:disabled {
background: #dddddd;
}
.btn-hl2:hover {
background-color: #e4b527;
}
.btn-hl3:hover {
background-color: #e4b527;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="TOSTORAGE" type="submit" class="btn-hl2 btn-common" name="TOSTORAGE">
<span aria-hidden="true"></span> TO STORAGE
</button>
<button id="TOULD" type="submit" class="btn-hl2 btn-common" name="TOULD">
<span aria-hidden="true"></span> TO ULD
</button>
<button id="TOTRAIN" type="submit" class="btn-hl2 btn-common" name="TOTRAIN">
<span aria-hidden="true"></span> TO TRAIN
</button>
<button id="TOARRIVAL" type="submit" class="btn-hl2 btn-common" name="TOARRIVAL">
<span aria-hidden="true"></span> TO ARRIVAL
</button>
<button id="TOHANDLER" type="submit" class="btn-hl3 btn-common" name="TOHANDLER">
<span aria-hidden="true"></span> TO HANDLER
</button>
试试这个:
$('button').click(function() {
$('button').not(this).prop('disabled', function(i, state) {
return !state;
});
});
button:disabled{
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>button 1</button>
<button>button 2</button>
<button>button 3</button>
<button>button 4</button>
( edit1 使用更好的选择器 .not( ) 而不是 .siblings( ) )
( edit2 简化解决方案)
Check this demo using jquery
.HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="TOSTORAGE" type="submit" class="btn-hl2" name="TOSTORAGE">
<span aria-hidden="true"></span> TO STORAGE
</button>
<button id="TOULD" type="submit" class="btn-hl2" name="TOULD">
<span aria-hidden="true"></span> TO ULD
</button>
<button id="TOTRAIN" type="submit" class="btn-hl2" name="TOTRAIN">
<span aria-hidden="true"></span> TO TRAIN
</button>
<button id="TOARRIVAL" type="submit" class="btn-hl2" name="TOARRIVAL">
<span aria-hidden="true"></span> TO ARRIVAL
</button>
<button id="TOHANDLER" type="submit" class="btn-hl3" name="TOHANDLER">
<span aria-hidden="true"></span> TO HANDLER
</button>
.JS
(function($) {
$.fn.enableDisable = function(){
return this.each(function(){
this.disabled = !this.disabled;
});
};
})(jQuery);
$('button').click(function(e) {
$('button').not(this).enableDisable();
});
小提琴演示
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 而循环只设置php中输入字段中的第一个值
- 使用 Javascript 将字段输入除以 12
- 合并来自多个字段输入的搜索结果
- 使用 Javascript 实时打印字段输入数据
- 防止AngularJS中跨路由的字段输入重复
- 引用Iframe中的字段输入
- 禁用html5”;“必需”;不显示窗体部分时的字段输入属性
- JavaScriptFormValidation-需要特定的字段输入,但使用大写/小写
- 验证VF页面上所需字段输入的Javascript不起作用
- 在没有
- 使用Jquery将字段输入值作为查询字符串附加到url
- HTML5 jQuery选择所有日期字段'输入:date'
- 将字段输入复制到另一个字段输入
- 向图像添加字段(输入)
- 动态添加字段输入不会存储值并传递给控制器
- 向输入字段输入键击
- 我如何通过javascript验证datetime字段输入
- HTML如何将用户字段输入作为json对象发送
- 如何根据'select' onchange事件将值填充到第二个输入字段?输入