2012-08-17 61 views
-1

奇怪的問題,在chrome和mozilla上測試過,它在safari $('input')中返回空值。我在這裏做錯了什麼?我的代碼如下

的Javascript:

function prepare_publisher_profile_input_fields(){ 
    var inputs = document.getElementsByTagName("INPUT"); 
    for (var i = 0; i < inputs.length; i++) { 
     if (inputs[i].type === 'submit') { 
      inputs[i].disabled = true; 
     } 
    } 

    var element = this; 

    $('input').click(function() { 
     $(this).removeAttr('readonly'); 
     $('input').removeAttr('disabled'); 
     $("#publisher_profile_save").removeAttr('disabled'); 
     $("#publisher_profile_save").bind('click', function() { 
      publisher_profile_save(); 
     }); 

     $("#publisher_profile_cancel").removeAttr('disabled'); 

     $("#publisher_profile_cancel").bind('click', function() { 
      publisher_profile_cancel(); 
     }); 
    }); 
} 

HTML:

<input type="text" name="company_name" value="" class="input-xlarge form-required" readonly="readonly" id="company_name"> 
<input type="text" name="username" value="" class="input-xlarge form-required" readonly="readonly" id="username"> 
<a href="#" id="publisher_profile_save" class="btn btn-primary pull-left" disabled="disabled">Save</a> 
<a href="#" id="publisher_profile_cancel" class="btn btn-primary pull-right" disabled="disabled">Cancel</a> 

請幫助。

+0

調用'$()** ** always **返回一個jQuery對象。它是什麼意思是返回「空」?發生了什麼,你期望會發生什麼?你想做什麼?究竟是什麼問題?你剛纔說了一些不起作用的東西,但我們甚至不知道代碼應該做什麼。 – 2012-08-17 02:38:13

+1

爲什麼混合使用jQuery的DOM操作函數? – davidbuzatto 2012-08-17 02:40:43

+1

如果你打算使用jQuery,你應該堅持使用jQuery,整點意思是說你不必做'document.getElementsByTagName(「INPUT」);'因爲你可以做'$('input ')' – Jeemusu 2012-08-17 02:41:42

回答

2

這些是錨定標記,而不是輸入標記。將$("input")選擇器更改爲$("a")

+0

編輯我的問題,我對這些輸入類型使用$('input') – 2012-08-17 02:59:12

+0

好吧,這樣做更有意義:P - 請按照@FelixKling的建議發佈jsfiddle。 – MicronXD 2012-08-17 03:05:44