9

我的 asp.net mvc 视图中有以下脚本:-

function disableform(id) {
    $('#' + id).prop("disabled", true);
}

但是上述功能只会禁用使用Internet Explorer的元素,但无法在chrome或firefox上运行,我也尝试写attr('disabled', 'disabled')而不是.prop("disabled", true);,但它没有解决问题。

我的 Jquery 版本是 1.7.1

那么可能是什么问题呢?

BR

4

4 回答 4

11

禁用表单是错误的!IE只是把它搞砸了!你应该禁用字段。

function disableform(id) {
    $('#' + id+' :input').prop("disabled",true);
}​

演示

于 2012-05-02T13:34:29.200 回答
1

我运行 ASP.NET 并遇到了同样的问题。

我放弃了 Jquery,转而使用纯 Javascript,效果很好。

    var element = document.getElementById('MyID');
    element.setAttribute('disabled', 'disabled');

编辑:要使其正常工作,您必须使用 element.removeAttribute('disabled'); 启用元素时。否则,它将保持禁用状态。

于 2013-06-04T21:00:32.370 回答
0

我无法让它在 chrome 中删除该属性,所以我只是添加了 disabled 类,它不是真正的禁用,但它适用于 IE 和 Chrome

$('#search').on('click', function (event) {
    $('#search').text("Searching");
    $('#search').addClass("disabled");
    return true;
});
于 2017-08-31T20:47:03.470 回答
-1
function SwapA(SwapActivation)  {
for (i=1;i==5;i++) {
if (i != SwapActivation) {
    // All Browsers supported .....
    $("input[name=pg1"+i+"]").prop('disabled', true);
    $("input[name=pg2"+i+"]").prop('disabled', true);
}
else {
    //   JQuery 1.10+ _&&_  Opera 12  and All other browsers...  !!!!
    if ( $("input[name=pg1"+i+"]").prop('disabled') === true)
        $("input[name=pg1"+i+"]").prop('disabled', false);
    if ( $("input[name=pg2"+i+"]").prop('disabled') === true)
        $("input[name=pg2"+i+"]").prop('disabled', false);

    //   works =  JQuery 1.10+ _&&_  Opera 12.16 + Firefox 24;
    //   do not work "Opera 17.0.1241.53", "Chrome" v.30.0.1599.101 m
    $("input[name=pg1"+i+"]").removeProp('disabled');
    $("input[name=pg2"+i+"]").removeProp('disabled');
    //   .removeProp() is affects negative

    //   works possible = JQuery 1.4.x  :
    $("input").attr('name','pg1'+i)[0].removeProp('disabled');
    $("input").attr('name','pg2'+i)[0].removeProp('disabled');
}}}

有用吗?:)

于 2013-10-23T20:11:31.357 回答