[英]How can I access the HTML element selected (monthpicker) in Javascript
I am using a monthpicker plugin for HTML page http://www.jqueryscript.net/demo/Minimal-jQuery-Month-Picker-Plugin-Simple-MonthPicker . 我为HTML页面http://www.jqueryscript.net/demo/Minimal-jQuery-Month-Picker-Plugin-Simple-MonthPicker使用monthpicker插件。 I am able to download and run it as expected.
我能够按预期下载并运行它。 However, I have issues in rendering the month that was selected by the user.
但是,在呈现用户选择的月份时遇到问题。 My HTML code is :
我的HTML代码是:
<body>
<input id="demo-1" type="text" />
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="monthpicker.js"></script>
<script>
$("#demo-1").Monthpicker({
dateFormat: 'yymmdd',
onSelect: function (dateText, inst) {
var dateStringForApi = $(this).val();
alert(dateStringForApi);
}
});
</script>
</body>
There's no alert when I select the month and year. 选择月份和年份时没有警报。 Can anyone tell me where am I going wrong ?
谁能告诉我我要去哪里错了? Please find attached the image for the more details.
请查看附件图片以获取更多详细信息。
PLNKR DEMO http://embed.plnkr.co/wui6hRg4E4gbAWPqbr6y/ PLNKR演示 http://embed.plnkr.co/wui6hRg4E4gbAWPqbr6y/
$(this).val();
is undefined. 未定义。
this
is the MonthPicker object in this scope which has no value attribute if you inspect it. this
是此范围内的MonthPicker对象,如果您检查它,则没有值属性。
Using $("#demo-1").val()
will return the value you are looking for. 使用
$("#demo-1").val()
将返回您要查找的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.