简体   繁体   中英

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 . 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 :

<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/

$(this).val(); is undefined. this is the MonthPicker object in this scope which has no value attribute if you inspect it.

Using $("#demo-1").val() will return the value you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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