简体   繁体   English

如何访问在JavaScript中选择的HTML元素(月选择器)

[英]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.

相关问题 使用Javascript选择链接时,如何隐藏HTML元素? - How can I hide a HTML element when a link is selected with Javascript? 如何根据仅使用javascript选中的复选框添加/删除html元素? - How can I add/remove an html element depending on a checkbox being selected with only javascript? 使用JavaScript和JQuery,如何维护动态更新的HTML选择元素的选定状态? - Using JavaScript and JQuery, How Can I Maintain the Selected State of a Dynamically-Updated HTML Select Element? 如何访问html元素的属性? - How can I access a property of an html element? 如何使用 JavaScript 获取元素的 HTML? - How can I get the HTML for an element with JavaScript? 如何在AngularJS中访问组合框的选定元素? - How can I access the selected element of a combobox in AngularJS? 如何根据可见性访问从 querySelectorAll 中选择的元素? - How can I access element selected from querySelectorAll based on visibility? 如何使用 javascript 根据其类型访问特定的 HTML 元素? - How can i access specific HTML element based on its type using javascript? 我如何访问 <html> Javascript中的元素? - How do I get access to the <html> element in Javascript? 如何使用id从javascript访问HTML元素,该html元素属于另一个html文档 - how do I access a HTML element from javascript using id,the html element belongs to another html document
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM