我有一组用于AM和PM的带有切换按钮的Time,但是在提交表单时,浏览器console.log中不存在AM或PM的值。 Console.log结果只是空白。
或者您有其他想法,允许用户选择AM / PM的时间。
我的代码如下。
var toggle = document.getElementById('container');
var toggleContainer = document.getElementById('toggle-container');
var toggleNumber;
toggle.addEventListener('click', function() {
toggleNumber = !toggleNumber;
if (toggleNumber) {
toggleContainer.style.clipPath = 'inset(0 0 0 50%)';
toggleContainer.style.backgroundColor = '#D74046';
} else {
toggleContainer.style.clipPath = 'inset(0 50% 0 0)';
toggleContainer.style.backgroundColor = 'dodgerblue';
}
console.log(toggleNumber)
});
<div class="row">
<div class="col-6">
<select id="time" class="form-control">
<option value=""> Hour </option>
<option value="1">1</option>
...
</select>
</div>
<div class="col-6 mb-20">
<div class="onoffswitch">
<input type="checkbox" name="ampm" class="onoff-checkbox" id="ampm">
<label class="onoffswitch-label" for="ampm">
<span id="am" class="onoffswitch-inner"></span>
<span id="pm" class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>