[英]How to disable all buttons but one, then enable all with click using jQuery?
I am trying to make a simple on/off switch with jQuery and it is disabling all buttons, including the on/off. 我试图用jQuery做一个简单的开/关开关,并且它禁用了所有按钮,包括开/关。
$(".onOff").click(function() {
$('button').not(this).prop('disabled', true);
});
How can I prevent this from disabling the button when clicked? 如何防止单击时禁用按钮?
Works for me, alternatively you can be specific inside the function using selector $('button:not(".onOff")')
对我有用,或者您可以使用选择器
$('button:not(".onOff")')
来指定函数内部的内容
$(".onOff").click(function() { $('button').not(this).prop('disabled', true); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button class="onOff">ON / OFF</button> <button>1</button> <button>2</button> <button>3</button> <button>4</button> <button>5</button>
Below the disable, try putting this: $(this).prop('disabled', false);
在禁用之下,尝试将其放置在下面:
$(this).prop('disabled', false);
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.