当点击时禁用按钮与JQuery的其他按钮
问题描述:
我有几个按钮的svg形式,你可以看到。当点击时禁用按钮与JQuery的其他按钮
var g = svg.append('g')
.attr('class', 'button')
.attr('id', 'deploy')
.attr('transform', 'translate(' + [buttonWidth/4, 100] +')');
var g2 = svg.append('g')
.attr('class', 'button')
.attr('id', 'savefile')
.attr('transform', 'translate(' + [buttonWidth/4, 150] +')');
var g3 = svg.append('g')
.attr('class', 'button')
.attr('id', 'loadfile')
.attr('transform', 'translate(' + [buttonWidth/4, 200] + ')');
1)我想禁用id为'savefile'的按钮,当点击id为'loadfile'的按钮时。我写了代码片段,因为它没有工作。什么价值可能会有问题?
function disableButton(disableVar)
{
console.log("disable button");
$(disableVar).prop("disabled", true);
}
我Load按钮就是这样:
button()
.container(g3)
.text(text3)
.count(2)
.cb(function() {
outer.attr("pointer-events", "none");
loadFlag = true;
clearFlag = false;
$(document).ready(function() {
$("#loadfile").click(function() {
var disableSaveFile = "#savefile";
disableButton(disableSaveFile);
});
});
update();
})();
2)我想启用又有“SAVEFILE”的ID,当我点击了“部署”的ID按钮按钮。以下代码也不适用于启用属性。我的禁用功能和部署按钮显示如下。我该如何解决这个问题?
button()
.container(g)
.text(text)
.count(0)
.cb(function() {
outer.attr("pointer-events", "none");
$('#deploy').click(function() {
var enableSaveFile = "#savefile";
enableButton(enableSaveFile);
});
});
});
})();
启用按钮功能
function enableButton(enableVar)
{
console.log("enable button");
$(enableVar).prop("enabled", true);
}
答
这是错误的:
这是如何禁用和用相同的按键方案正确启用按钮,现在你只需要把它翻译成sgg
$("#first").click(function(){
$("#second").prop("disabled",true);
});
$("#third").click(function(){
$("#second").prop("disabled",false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="first">Click me</button>
<button type="button" id="second">Disable me</button>
<button type="button" id="third">All available</button>
答
<button class="bothButtons">Click A</button>
<button class="bothButtons">Click B</button>
定义与类
$('.bothButtons').on('click', function(){
$('.bothButtons').prop('disabled', true);
$(this).prop('disabled', false);
});
使用jQuery两个按钮: $( 'btn.btn-small.btn原色。')点击(函数(){ 。 $('。btn.btn-small.btn-primary')。not($(this))。prop('disabled',true) }); –
它不适合我。当我需要将这个参数设置为'.btn.btn-small.btn-primary'时,你的意思是什么? – zoint