[英]Why clicking on my button don't alert range selected?
I' ve a button, so when user clicks it, it should alert range selected.我有一个按钮,所以当用户单击它时,它应该选择警报范围。 If user didn't change the range selected (slider) default value 1 should be alerted.如果用户未更改所选范围(滑块),则应提醒默认值 1。
Why is not alerting it?为什么不提醒它?
Codepen:代码笔:
https://codepen.io/ogonzales/pen/abNQXLg https://codepen.io/ogonzales/pen/abNQXLg
Error: it should only alert 1 value:错误:它应该只提醒 1 个值:
JS:记者:
$('#step_one_siguiente').on('click', function () {
let val = this.value;
alert($("#performance_options").prop("selected", true).text());
});
Here is a workaround that might be helpful.这是一个可能有用的解决方法。
let ranges = ['1080p','1440p','2k']
$('#step_one_siguiente').on('click', function () {
var index = parseInt($('input').val()) - 1
alert(ranges[index]);
});
I think it is because the way you use the syntax of the datalist is incorrect.我认为这是因为您使用数据列表语法的方式不正确。 Values are not meant to be between the option tags but only in the value="" attribute.值不应该在选项标签之间,而只能在 value="" 属性中。 However for this to work, the input value would need to match the list value, which is not compatible with a range control as the values you want are not a sequence.但是,要使其工作,输入值需要与列表值匹配,这与范围控件不兼容,因为您想要的值不是序列。
https://www.w3schools.com/tags/tag_datalist.asp https://www.w3schools.com/tags/tag_datalist.asp
Based on Ibrahim question, I was able to come up with:基于易卜拉欣的问题,我能够想出:
Apparently I don't have to search for a selected range, as it only returns the value of the selected one.显然我不必搜索选定范围,因为它只返回选定范围的值。
<script>
$('#step_one_siguiente').on('click', function () {
alert($('[type="range"]').val());
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.