我在我的应用程序中使用jquery中的这个委托事件处理函数。 并且它的工作正常。现在我想要除了当前的按钮之外已经创建的所有按钮。
我该怎么做
$('#form').on('click', '.button', function(){
var temp = '<input type="button" class="button" />'
$('#form').append(temp);
})
答案 0 :(得分:4)
插入新按钮后:
var temp = $('<input type="button" class="button" />');
$('#form').append(temp);
$('#form .button').not(temp).prop('disabled', true);
请注意,我在按钮的定义周围添加了$()
,因此它是一个元素而不是HTML字符串(在.not()
中不起作用)。
或者你也可以在插入按钮之前运行它:
$('#form .button').prop('disabled', true);
禁用所有按钮 - 但由于新按钮不是表单的一部分但它不会被禁用
答案 1 :(得分:1)
尝试
var $form = $('#form').on('click', '.button', function(){
$form.find('.button').prop('disabled', true)
var temp = '<input type="button" class="button" />'
$form.append(temp);
})
答案 2 :(得分:0)
$('#form').on('click', '.button', function(){
var temp = '<input type="button" class="button" />'
$("#form").find(".button").prop("disabled",true).end().append(temp);
})