2

我在我的应用程序的 jquery 中使用了这个委托的事件处理函数。并且工作正常。现在我想禁用除当前按钮之外的所有已创建按钮。

我怎么做

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

3 回答 3

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);

这会禁用所有按钮 - 但由于新按钮不是表单的一部分,但它不会被禁用

于 2013-09-17T12:25:12.480 回答
1

尝试

var $form = $('#form').on('click', '.button', function(){
    $form.find('.button').prop('disabled', true)
    var temp = '<input type="button" class="button" />'
    $form.append(temp);
})
于 2013-09-17T12:25:24.343 回答
0
$('#form').on('click', '.button', function(){
    var temp = '<input type="button" class="button" />'
     $("#form").find(".button").prop("disabled",true).end().append(temp);
})
于 2013-09-17T12:25:15.230 回答