【问题标题】:cannot view calendar in HTML table无法在 HTML 表格中查看日历
【发布时间】:2013-05-21 05:22:59
【问题描述】:

我有一个 html 表,其中包含 startDateendDate。我想在单击这些文本框时显示日历以选择日期。然后我们从该日历中选择一个日期,然后所选日期将显示在该文本框中。我使用了以下代码。但这不起作用,也没有显示任何错误。这段代码有什么问题?我需要在这段代码中做哪些修改?或者在这些字段中查看日历视图的最佳方式是什么?

<!DOCTYPE html>
<html>
<body>
<script src="http://localhost/js/jquery.js"></script>
<script src="http://localhost/js/jqueryUI.js"></script>

<script> 
function calendar1(){
         $( "#startDate" ).datepicker();   
}
</script>

<table id='tblAppend' bgcolor='#D2DFEF'><col width='170'><col width='30'><tr><td>Portfolio Name:</td><td><input type='text' name='name'></td></tr>
<tr><td>start date</td><td><input type='text' name='startDate' onclick='calendar1();'/></td></tr>
<tr><td>start date</td><td><input type='text' name='endDate' onclick='calendar1();'/></td></tr>
</table>
</body>
</html>

【问题讨论】:

  • 您缺少 UI 的 CSS。
  • 添加了 css。但它仍然无法正常工作。
  • 除此之外,您应该尝试 rajesh 的回答 - 只需在 DOM 就绪 ($(function(){});) 上调用 $(selector).datepicker() 而不是那些 onclicks 就可以了。否则检查 JS 控制台(Chrome 上的 F12 或带有 Firebug 的 Firefox 上),脚本可能无法正确加载。
  • 好的..谢谢您的帮助。

标签: jquery html calendar datepicker


【解决方案1】:

试试这样的,工作FIDDLE

HTML 代码

<p>Date: <input type="text" id="startDate" /></p>
<p>Date: <input type="text" id="endtDate" /></p>

查询代码

 $(function () {
    $("#startDate , #endtDate").datepicker();
});

【讨论】:

    猜你喜欢
    • 2019-12-31
    • 2014-05-16
    • 1970-01-01
    • 2012-10-24
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多