2011-02-25 99 views
1
if ($("#IndicationCalculatorGroupId option:selected").text() == 'Create a New Group') 
       { 
        $("#newGroupNameRow").show(); 
       } 

      $("#IndicationCalculatorGroupId").change(function() { 
       if ($("#IndicationCalculatorGroupId option:selected").text() == 'Create a New Group') 
       { 
        $("#newGroupNameRow").show(); 
       } 
       else{ 
        $("#IndicationCalculatorNewGroupName").val(''); 
        $("#newGroupNameRow").hide(); 
       } 
      }); 

我在文檔中準備好了。基本上當頁面加載時,我想檢查一下是否有一個特定的值,如果它確實顯示特定的div。 onChange()事件正常工作,所以我知道檢查正確完成,它似乎不工作onDocumentReady。 div不會顯示()。JQuery沒有在Document Ready上執行

我做錯了什麼?

回答

2

我想你可能會錯過:

要設置「IndicationCalculatorGroupId」的默認選擇的值,你需要調用

$("#IndicationCalculatorGroupId").change() 

你改變功能後的變化情況來執行登錄。

0

我在這裏試過你的代碼http://jsfiddle.net/DkZpB/,它似乎工作正常。我注意到的一件事是,當我在<div id="newGroupNameRow">上使用內聯樣式時,.show()方法沒有做任何事情。我不得不通過CSS設置display:none,或者撥打.hide()作爲$(document).ready()上的第一件事。

+0

似乎沒有css工作http://jsfiddle.net/DkZpB/1/ – Rafay 2011-02-25 19:34:12

+0

雅,我只是說,如果他想隱藏初始狀態,它需要通過CSS或'.hide()完成。 ',而不是內聯樣式。 – ggutenberg 2011-02-25 19:37:31