简体   繁体   English

我如何使用带有图标的jquery datepicker的文本框

[英]How I use a textbox with jquery datepicker with icon

I want use jquery datepicker in my asp.net application but it don't work 我想在我的asp.net应用程序中使用jquery datepicker,但是它不起作用

in my Project is a Folder (images) with Calender.ico 在我的项目中是Calender.ico的文件夹(图像)

here my code in master.master: 这是我在master.master中的代码:

 <script>

        $(function () {
            $("#txtVon").datepicker({
                showOn: 'button',
                buttonImage: '/images/Calender.ico', 
                buttonImageOnly: true,
                dateFormat: "mm-dd-yy"
            });
        });

       </script>

here my code in createuser.aspx 这是我在createuser.aspx中的代码

<asp:TextBox ID="txtVon" runat="server" ReadOnly="True" ></asp:TextBox>

How I make wrong? 我怎么做错了? I don't see the icon 我没有看到图标

I think it's the ID of your textbox. 我认为这是您的文本框的ID。 You write txtVon , but ASP.NET renders something different. 您编写了txtVon ,但是ASP.NET呈现了一些不同的东西。 So client side the ID is more likely to be something like C001_txtVon . 因此,客户端ID更有可能是C001_txtVon之类的东西

So it's better to give your textbox a CssClass like cDatePicker and use that in your jQuery selector. 因此,最好为您的文本框提供一个类似于cDatePicker的CssClass,并在jQuery选择器中使用它。

Or make your ID selector a bit more fuzzy, like $("input[id*='txtVon']").datepicker({}); 或者使您的ID选择器更加模糊,例如$("input[id*='txtVon']").datepicker({});

And as a last note; 最后一点; you'd best use a .png file instead of .ico, because i don't think that .ico is supported correctly by all browsers. 您最好使用.png文件而不是.ico,因为我认为并非所有浏览器都正确支持.ico。

http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support

If you want datepicker to be visible on icon click as well? 如果您还希望在图标上显示日期选择器,也请单击? Here is what I do: 这是我的工作:

<input id='invdate' name='invdate' type='text'/>
<span style='padding:5px'><img id='dpimage' alt="img" src='calendar2.gif'></span>

$(function() {
  $("#invdate").datepicker();
  $("#dpimage").click(function () {
    $("#invdate").datepicker("show")
  });
});

Demo 演示版

instead of this 代替这个

'/images/Calender.ico

place a non.ico image ie like eg: calender.gif..something like that 放置一个非.ico图像,例如:calender.gif ..类似的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM