可以通知datalist所选选项的值,值为:1、2或3。
根据this other question的说法,它应该按原样工作。
Codepen:
https://codepen.io/ogonzales/pen/gOMZarJ
HTML:
<div class="__range __range-step __range-step-popup">
<input value="1" type="range" max="3" min="1" step="1" list="performance_options">
<datalist id="performance_options">
<option value="1">1080p</option>
<option value="2">1440p (2k)</option>
<option value="3">4K</option>
</datalist>
<output class="__range-output-square"></output>
</div>
联署材料:
alert($('#performance_options').attr('value'));
警报“未定义”,预期为1、2或3。
发布于 2020-11-11 15:53:49
如果你想提醒任何选项你应该选择它..。
这将提醒第一个人:
alert($('#performance_options option').attr('value'));
这将提醒他们所有人:
$('#performance_options option').each(function(index, value) {
alert(`option${index}: ${this.value}`);
});
由于您想要通知用户选择的选项,所以您应该侦听输入更改值,并通知相同的选项文本:
$('[type="range"]').on('change', function() {
let val = this.value;
alert($("#performance_options option[value=" + val + "]").prop("selected", true).text());
});
https://stackoverflow.com/questions/64795720
复制相似问题