2012-05-02 7 views
7

で働いていない私は私のasp.net MVCのビュー内の次のスクリプトを持っている: -prop( "disabled"、true);およびattR(「無効」「無効」)は、クロムとFirefox

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

しかし、上記の機能要素のみを無効にしますインターネットエクスプローラを使用して、しかし、クロムやFirefoxで動作するように失敗する、私はまた.prop("disabled", true);の代わりにattr('disabled', 'disabled')を書き込もうとしましたが、それは問題を解決しませんでした。

私のjQueryのバージョンは、だから何が問題かもしれません1.7.1

のですか?

BR

+2

上で動作します'alert '($('# '+ id).length)' –

+0

両方ともクロムでうまくいくようです: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

私はそれがプロパティを削除クロームで動作させることができなかったので、私はちょうど無効にクラスを追加し、それは本当無効になっていないですが、あなたがこれを置けば、それはIEとChrome

$('#search').on('click', function (event) { 
    $('#search').text("Searching"); 
    $('#search').addClass("disabled"); 
    return true; 
}); 
関連する問題