2012-05-02 76 views
7

工作,我有我的asp.net mvc的视图中下面的脚本: -prop(“disabled”,true);和attR(“禁用”,“禁用”)未在Chrome和Firefox

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

但上面的功能将只禁用元素使用Internet Explorer,但将无法在Chrome或Firefox上工作,我也试着编写attr('disabled', 'disabled')而不是.prop("disabled", true);,但它没有解决问题。

我的jQuery的版本是1.7.1

那么可能是什么问题?

BR

+2

在这个函数中,你会得到什么:'alert($('#'+ id).length)' –

+0

这两个在Chrome中似乎都很好用:http://jsfiddle.net/Fuw49/ –

回答

8

禁用形式是错误的! IE只是搞乱它!你应该禁用字段。

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

DEMO

1

我运行ASP.NET和有同样的问题。

我放弃了jquery,去了纯Javascript,它工作得很好。

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

编辑:为了这个工作正常,你必须使用element.removeAttribute('disabled');当启用该元素时。否则它仍然被禁用。

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

有用吗? :)

0

我不能让它在Chrome浏览器中除去的财产,所以我刚才添加的禁用类,它是不是一个真正的禁止,但如果你把这个它适用于IE和Chrome

$('#search').on('click', function (event) { 
    $('#search').text("Searching"); 
    $('#search').addClass("disabled"); 
    return true; 
}); 
相关问题