在jQuery对话框中显示jquery datepicker
问题描述:
所以我有datepicker在正常窗口中工作得很好,但我不能在我的生活中使用 让它在对话框中工作。在jQuery对话框中显示jquery datepicker
我有一些JavaScript,打开我的application.js对话框文件 以及在日期选择器JS 如下:
$(function() {
$("#version_release_date").datepicker({dateFormat: 'yy-mm-dd'});
});
$(document).ready(function() {
$('a.popup').click(function() {
$('<div />').appendTo('body').load($(this).attr('href') + '
form').dialog({
title: $(this).text()
})
});
return false;
});
});
现在第一功能工作正常,如果我只是去直接到页面 ,但是如果通过对话框中的第二个函数呈现页面,则不会再出现日期选择器 。
这是在创建对话框:
<%= link_to 'Close Escalation', new_version_path, :class => 'popup' %>
这些都是我的包括
<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>
<%= javascript_include_tag "jquery.rails.js" %>
任何帮助表示赞赏。基本上从我可以告诉我不能得到 任何JavaScript工作在对话框中。
我甚至尝试将脚本添加到页面,但这并不工作 要么。
这是在rails应用程序中。
答
<div id="mydialog"></div>
<a href="/url/" class="popup">title text</a>
和jQuery
$(function(){
$('a.popup').click(function(event) {
// prevent link from going to href
event.preventDefault();
// empty the contents of the dialog and load new content
$('#mydialog').empty().load($(this).attr('href') + 'form');
/*apply datepicker to input , i'm assuming this gets loaded in the above line if not dont' put it here
if its the documet and not loaded you don't want to apply it multiple times
*/
$("#version_release_date").datepicker({dateFormat: 'yy-mm-dd'});
//set the title of the dialog
$('#mydialog').dialog('option', 'title', this.text);\
//open the dialog
$('#mydialog').dialog('open');
});
//setup the dialog but don't open it yet
$('#mydialog').dialog({autoOpen: false});
});
嗯没有什么,当我点击演示标题文本在对话框中。 – Dalupus 2011-05-07 04:13:43
正确,因为它会加载href,但我没有href加载 – mcgrailm 2011-05-07 13:23:35
让我弹出它,看看会发生什么。谢谢 – Dalupus 2011-05-07 14:40:39