最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Jquery datepicker calendar icon positioning - Stack Overflow

matteradmin4PV0评论

I'm using the jquery-ui datepicker. The problem is, the library inserts the calendar icon straight after the input field by default. But my HTML markup is a bit different and I want the calendar icon to appear somewhere else in the DOM, i.e. outside the parent container of the input field.

I even tried to add my own <img/> manually and added the class ui-datepicker-trigger, but it doesn't trigger anything.

How can I decide where the icon should appear in the DOM and it has to work?

This is what I want:

<div class="parent">
    <input id="datepicker" class="hasDatepicker" type="text" />
</div>

<img class="ui-datepicker-trigger" src="images/calendar.gif" alt="..." title="..." />

Not this (default jquery-ui insertion):

<input id="datepicker" class="hasDatepicker" type="text" />
<img class="ui-datepicker-trigger" src="images/calendar.gif" alt="..." title="..." />

Many thanks

I'm using the jquery-ui datepicker. The problem is, the library inserts the calendar icon straight after the input field by default. But my HTML markup is a bit different and I want the calendar icon to appear somewhere else in the DOM, i.e. outside the parent container of the input field.

I even tried to add my own <img/> manually and added the class ui-datepicker-trigger, but it doesn't trigger anything.

How can I decide where the icon should appear in the DOM and it has to work?

This is what I want:

<div class="parent">
    <input id="datepicker" class="hasDatepicker" type="text" />
</div>

<img class="ui-datepicker-trigger" src="images/calendar.gif" alt="..." title="..." />

Not this (default jquery-ui insertion):

<input id="datepicker" class="hasDatepicker" type="text" />
<img class="ui-datepicker-trigger" src="images/calendar.gif" alt="..." title="..." />

Many thanks

Share Improve this question asked Apr 25, 2013 at 10:15 ShaozShaoz 10.7k26 gold badges76 silver badges100 bronze badges 3
  • 1 @Kasyx, I don't want to do that because, that's what causes the insertion straight after <input/>. That's what I asked in the question, how to cancel that default behaviour... – Shaoz Commented Apr 25, 2013 at 10:19
  • Yes sorry, my fault. Now i understand your problem. – Kasyx Commented Apr 25, 2013 at 10:22
  • No problem, it's cool. – Shaoz Commented Apr 25, 2013 at 10:23
Add a ment  | 

2 Answers 2

Reset to default 2

Try to manually add trigger which will show datepicker on image click:

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

try this

$(selector).datepicker({showOn: 'button', buttonImage: 'img/cal.gif',
      buttonImageOnly: true, buttonText: 'Open calendar'});

SEE HERE

Post a comment

comment list (0)

  1. No comments so far