2012-05-02 117 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; 
}); 
相關問題