2010-08-19 79 views
0

這個問題主要是在標題中總結出來的。如果display:none,Internet Explorer將不會觸發點擊功能;

該網站位於:http://tinyurl.com/3abbcsr

我使用的是自定義的無線電/複選框代碼accessible_custom_designed_checkbox_radio_button_inputs_styled_css_jquery/

這是其代碼的JIST(我修改了它允許定義不同的風格不同標籤上的標題

$(this).each(function(i){ 
     if($(this).is('[type=radio]')){ 
      var input = $(this); 

      // get the associated label using the input's id 
      var label = $('label[for='+input.attr('id')+']'); 


      var labelTitle = label.attr('title'); 

      // wrap the input + label in a div that has class "custom-radio-LabelTitle" 
      $('<div class="custom-radio-' + labelTitle + '"></div>').insertBefore(input).append(input, label); 


      // find all inputs in this set using the shared name attribute 
      var allInputs = $('input[name='+input.attr('name')+']'); 


      //bind custom event, trigger it, bind click,focus,blur events     
      input.bind('updateState', function(){ 
       if (input.is(':checked')) { 
        if (input.is(':radio')) {    
         allInputs.each(function(){ 
          $('label[for='+$(this).attr('id')+']').removeClass('checked'); 
         });  
        }; 
        label.addClass('checked'); 
       } 
       else { label.removeClass('checked checkedHover checkedFocus'); } 

      }) 
      .trigger('updateState') 
      .click(function(){ 
       $(this).trigger('updateState'); 
      }) 
     } 
    }); 

從我的理解,他們的代碼基本上查找所有收音機輸入,然後定義一個叫做updateState的特殊觸發器。然後他們在輸入的點擊功能中觸發它。

因此,每次單擊輸入單選按鈕時,updateState都會觸發,然後爲該單選按鈕的標籤設置一個類。類的改變會改變標籤的CSS。

單擊標籤時,也會單擊該標籤的輸入(運行jQuery的.click()函數)。

我所做的是將我所有的輸入單選按鈕設置爲display:none。這樣用戶只需點擊該標籤,並且祕密地​​點擊了一個單選按鈕。

如果輸入被隱藏,則.click()函數將不會爲輸入運行。

我認爲有兩種方式傳遞這樣的:

一個),而不是有無線的。點擊()函數觸發handlestate,有標籤的。點擊()函數處理它來代替。這可能無法正常工作,因爲那時單選按鈕可能實際上沒有被點擊(這弄亂了我的表單)

b)當單擊標籤時,手動觸發收音機的點擊功能。但是,這可能會導致它在每個瀏覽器中被觸發兩次,但IE。我不知道如何引用標籤的廣播,也不知道如何停止觸發兩次。

回答

0

我得到了我想要有:

$("label[title='Plan']").click(function() { 
    var id = $(this).attr('for') 
    $("input[id='"+id+"']").trigger("click"); 
    $("input[id='"+id+"']").trigger("updateState"); 
    PlanChange(); 
}); 

然後刪除了所有onClicks。

1

一個),而不是有無線的 。點擊()函數觸發 handlestate,有標籤的。點擊()函數 處理它來代替。這可能 沒有工作,雖然正確,因爲那時 的單選按鈕實際上可能沒有 點擊(它弄亂了我的形式)

這可能工作的權利,你的標籤的。點擊()觸發也迫使無線電按鈕進行檢查這樣的,

$('#radiobutton').attr('checked', 'checked'); 
+0

爲我工作! – 2012-07-20 16:41:00