[英]Call jQuery UI Datepicker from another function
The following is my code: 以下是我的代码:
<script type="text/javascript">
$(function(){ //this is the datepicker function
$( "#datepicker" ).datepicker();
});
function jsFunction(){
// i want to call the datepicker function from here
}
</script>
</head>
html HTML
<html:image alt="Calendar" src="/images/icon_calendar.gif"
value="reset" onclick="jsFunction();" />
<input type="text" id="datepicker" />
When I click on the text box, the text box will prompt a calendar to let me choose the date. 当我单击文本框时,文本框将提示日历让我选择日期。 This date picker is working fine.
这个日期选择工作正常。
I added in an image, and I want the text box to prompt the calendar when I click on the image instead of click on the text box. 我添加了一个图像,我希望文本框在我单击图像时提示日历,而不是单击文本框。 I would like to ask how to call the datepicker jquery from the onlick=jsFunction();
我想问一下如何从onlick = jsFunction()调用datepicker jquery; .
。
I an working in Java Struts2 framework. 我在Java Struts2框架中工作。
Kindly advise/ help. 请提供建议/帮助。
Correct way to set an icon trigger (via API): 设置图标触发器的正确方法(通过API):
$( "#datepicker" ).datepicker({
showOn: "button",
buttonImage: "/images/icon_calendar.gif",
buttonImageOnly: true
});
http://jqueryui.com/datepicker/#icon-trigger http://jqueryui.com/datepicker/#icon-trigger
You can use the show method 您可以使用show方法
function jsFunction(){
$( "#datepicker" ).datepicker( "show" );
}
Try 尝试
function jsFunction(){
$( "#datepicker" ).focus();
}
or 要么
function jsFunction(){
$( "#datepicker" ).click();
}
<script>
$(function() {
$("#datepic").datepicker({ showOn: 'button',buttonImage: 'image/calendar.gif'});
});
</script>
<input type="text" id="datepic" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.