2011-02-25 101 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