![](/img/trans.png)
[英]PHP get "min, max, step and value" variables from plugin to quantity box Woocommerce
[英]Get max,min value from select box Jquery
嘿朋友。 我在从选择框(html)获取最大值和最小值时遇到了问题。 我想用jquery或javascript从selectbox中获得MAX AND MIN值。
这是标记,简单范围滑块。
$('#slider').slider({
range: true,
min: 0,//HERE I WANT TO GET VALUES
max: 40,
step: 10, // Use this determine the amount of each interval
values: [ 20, 40 ], // The default range
slide: function( event, ui ) {
// for input text box
$( "#amount" ).val( ui.values[ 0 ] + " - " + ui.values[ 1 ] );
// Display and selected the min Price
$( "#my_min" ).val(ui.values[ 0 ]);
// Display and selected the max Price
$( "#my_max" ).val(ui.values[ 1 ]);
}
});
我想从选择框中获取它们,选择框将由PHP动态填充。 这是代码:
<select id="my_min" class="price_range">
<?php //dynamicly filled options
while($row=mysql_fetch_array($query))
{echo "<option>".$row['values']."</option>";}
?>
</select>
感谢帮助。
您的问题不明确。 两种解释方式:
1.您希望javascript知道选择框的最小值和最大值。
您可以使用:
var options = document.getElementById('yourselectbox').childNodes;
var min = 999999999;
var max = 0;
for(var i = 0; i < options.length; i++) {
if(options[i].value > max) max = options[i].value;
if(options[i].value < min) min = options[i].value;
}
2.您希望服务器知道javascript的最大值和最小值。
DOM由服务器构建,即,它构建HTML。 HTML包含定义最小值和最大值的javascript。 通过POST将数据发送回服务器时,将仅发送SET值。 通常,最小值和最大值对服务器无关紧要。 如果要发送最小值和最大值,则必须制作包含这些值的隐藏输入字段。 但是,为什么呢? 您定义最小值和最大值不是吗?
-编辑-
var options = document.getElementById('yourselectbox').childNodes;
var min = 999999999;
var max = 0;
for(var i = 0; i < options.length; i++) {
if(options[i].value > max) max = options[i].value;
if(options[i].value < min) min = options[i].value;
}
$('#slider').slider({
range: true,
min: min,
max: max,
step: 10, // Use this determine the amount of each interval
values: [ 20, 40 ], // The default range
slide: function( event, ui ) {
// for input text box
$( "#amount" ).val( ui.values[ 0 ] + " - " + ui.values[ 1 ] );
// Display and selected the min Price
$( "#my_min" ).val(ui.values[ 0 ]);
// Display and selected the max Price
$( "#my_max" ).val(ui.values[ 1 ]);
}
});
根据$ row [“ values”]格式,您可以像这样首先获得max和min值,首先将所有选项文本都放入数组中,并使用parseInt()作为Int传递,然后执行
OptionsArray.maximum = function(ArrayParameter){
return Math.max.apply( Math, ArrayParameter);
};
OptionsArray.minimum = function(ArrayParameter){
return Math.min.apply( Math, ArrayParameter);
};
console.log('Maximum is '+OptionsArray.maximum);
console.log('Minimum is '+OptionsArray.minimum);
希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.