[英]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.