简体   繁体   English

禁用所有以前创建的按钮,除了当前用jQuery

[英]disable all previous created button except current one with jquery

I am using this delegated event handler function in jquery in my application. 我在我的应用程序的jquery中使用此委托事件处理程序函数。 and its working fine.Now I want to desable all the button already created except current one. 现在,我想禁用除当前按钮之外的所有已创建按钮。

How do i do that 我怎么做

$('#form').on('click', '.button', function(){
var temp = '<input type="button" class="button" />'
$('#form').append(temp);
})

After inserting the new button: 插入新按钮后:

var temp = $('<input type="button" class="button" />');
$('#form').append(temp);
$('#form .button').not(temp).prop('disabled', true);

Please note that I added $() around the definition of the button so it's an element and not a HTML string (which would not work in .not() ). 请注意,我在按钮的定义周围添加了$() ,因此它是一个元素,而不是HTML字符串(在.not()不起作用)。

Alternatively you can also run this before inserting the button: 另外,您也可以在插入按钮之前运行此命令:

$('#form .button').prop('disabled', true);

That disables all buttons - but since the new one is not part of the form yet it won't be disabled 这会禁用所有按钮-但由于新按钮不是表单的一部分,因此不会被禁用

Try 尝试

var $form = $('#form').on('click', '.button', function(){
    $form.find('.button').prop('disabled', true)
    var temp = '<input type="button" class="button" />'
    $form.append(temp);
})
$('#form').on('click', '.button', function(){
    var temp = '<input type="button" class="button" />'
     $("#form").find(".button").prop("disabled",true).end().append(temp);
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果除一个以外的所有输入和文本区域均为空,请禁用表单提交按钮 - Disable form submit button if all input and textarea are empty except one 在 JQuery 日期选择器中禁用除一个特定日期之外的所有过去日期 - To disable all past dates except one particular date in JQuery datepicker jQuery:如何向除当前页面外的所有div添加类 - jQuery: how to add class to all divs on page except current one 禁用除最后一个之外的所有先前复选框,启用其他复选框 - Disable all previous checkboxes except last one, enable preceding checkbox when other enabled jQuery:禁用除当前复选框之外的所有复选框 - jQuery: Disable all checkboxes apart from current one 我将如何选择所有具有相同名称的div类,但使用jQuery / javascript的当前div除外? - How would I select all div classes with the same name except the one in the current div with jquery/javascript? Jquery 选择上一个单选按钮值而不是当前值? - Jquery selecting previous radio button value and not current? jQuery获取前一个值而不是当前值 - jquery grabs the previous value instead of current one jQuery当前单选按钮单击它在jqgrid中禁用 - Jquery Current radio button click it disable in jqgrid ES6 / Typescript OnClick将类添加到除单击按钮之外的所有TD内的第一个按钮(无jQuery) - ES6 / Typescript OnClick add a class to all the TD's inside the clicked button except the first one (No jQuery)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM