在jquery中禁用链接按钮

时间:2012-09-11 07:16:09

标签: jquery asp.net-mvc button

我在网站上使用了链接按钮。在启动时,应禁用“删除”按钮。单击“添加”按钮后,将启用它。但我无法实现。我不知道我犯了什么错。任何一个请更正?

enter code here

if ($('.' + inputContainerCss).length < 3) {
    //    if ($('.' + inputContainerCss).length < 2) {
    $('#' + btnDelId).attr('disabled', 'disabled');
}

  $('#' + btnAddId).click(function () {
    var num = $('.' + inputContainerCss).length; // how many "duplicatable" input fields we currently have
    var newNum = new Number(num + 1);   // the numeric ID of the new input field being added

    // create the new element via clone(), and manipulate it's ID using newNum value
    var newElem = $('#' + inputContainerIdPrefix + num).clone().attr('id', inputContainerIdPrefix + newNum);

    // manipulate the name/id values of the input inside the new element
    //newElem.children(':first').attr('id', firstChildInputIdPrefix + newNum).attr('name', firstChildInputIdPrefix + newNum);


    newElem.children().each(function () {
        var idPrefix = $(this).attr('id').substring(0, $(this).attr('id').length - 1);
        var namePrefix = $(this).attr('name').substring(0, $(this).attr('name').length - 1);
        $(this).attr('id', idPrefix + newNum).attr('name', namePrefix + newNum);
    })

    // insert the new element after the last "duplicatable" input field
    $('#' + inputContainerIdPrefix + num).after(newElem);

    // enable the "remove" button
    $('#' + btnDelId).attr('disabled', '');

1 个答案:

答案 0 :(得分:1)

这不是您的编码问题。您必须为此添加一些jquery文件,如

Just clik the link and download it.