The code on the official site that retrieves the status of the switch does not work.

Asked 1 years ago, Updated 1 years ago, 54 views

Switch state acquisition" on the official website doesn't seem to work even if it's copied. Has the specification changed?
html

<ons-switchid="switch-1">/ons-switch>

JS

var switch= document.getElementById('switch-1');
ons.notification.alert('Value is' + switch.checked);

onsen-ui

2022-09-30 15:51

1 Answers

The HTML(?) listed as an example on the Switch State Retrieval page on the official site (https://ja.onsen.io/v2/api/js/ons-switch.html) does not have an element with the ID switch-1 (or no element with the ID specified).(as of March 16, 2020 at 10:55)

Therefore, switch= document.getElementById('switch-1'); gets nothing and
When I tried to display switch.checked, was there an error?


2022-09-30 15:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.