2011-10-28 48 views
1

在我的rails想设置jQuery和jQuery UI的3.1.1应用为什么我的JS jQuery不工作?

在我看来,我有

<a href="#" id="test_link1">Test</a> 

<div id="dialog-modal" title="Basic modal dialog" style="display:none;"> 
<p>Adding the modal overlay screen makes the dialog look more prominent because it dims out the page content.</p> 
</div> 

<script type="text/javascript"> 
    $("#test_link1").click(function() { 
    ('#dialog-modal').dialog(); 
    }); 

它不工作。当我检查我得到

storages:105TypeError: 'undefined' is not a function (evaluating '('#dialog-modal').show()') 
     }); 

在application.js中。文件被加载

//= require jquery 
//= require jquery_ujs 
//= require jquery-ui.min 

回答

4

变化('#dialog-modal').dialog();

$("#dialog-modal").dialog();

你就忘记了jQuery($),所以没有jQuery对象一起工作。

3

您需要添加一个美元符号:

$('#dialog-modal').dialog(); 
+0

我傻,但错误依然存在。这是什么意思? – Gaelle

+0

应该是一个不同的错误,但你可以尝试将它包装在文档就绪函数'$(function(){// put code here});' – swatkins

+0

包装但是当我点击链接时出现同样的错误 – Gaelle

2

总结你的代码准备好处理:

$(function(){ 
    $("#test_link1").click(function() { 
    $('#dialog-modal').dialog(); 
    }); 
}); 
+0

仍然忘记$('#dialog-modal“)。dialog();' – Sam

+1

@SamStriano:在看到您的评论之前更新:) – Sarfraz

+0

感谢但错误仍然存​​在''给出'存储:106TypeError:'undefined'不是一个函数(评估'$('#dialog-modal')。dialog()')' – Gaelle