3 回答
TA贡献1878条经验 获得超4个赞
如果您的代码正是您在问题中包含它的方式,那么您就有了一些语法错误。首先,您需要删除导致这些错误的错误空格。此外,您应该input使用其value属性访问元素的值,而不是innerText.
修复这些项目,这似乎有效:
var btnEstablecer = document.getElementById("establishList");
btnEstablecer.addEventListener("click", function() {
let minPric = parseInt(document.getElementById("input_price-minList").value);
let maxPric = parseInt(document.getElementById("input_price-maxList").value);
console.log(minPric, maxPric);
});
<div class="filter-price">
<input class="input_price-min" id="input_price-minList" type="value" placeholder="Min">
<input class="input_price-max" id="input_price-maxList" type="value" placeholder="Max">
<button class="establish-button" id="establishList">Submit</button>
</div>
TA贡献1804条经验 获得超2个赞
使用 .value 属性而不是内部文本。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div class="filter-price">
<input
class="input_price-min"
id="input_price-minList"
type="number"
placeholder="Mínimo"
/>
<input
class="input_price-max"
id="input_price-maxList"
type="number"
placeholder="Máximo"
/>
<button class="establish-button" id="establishList">Establecer</button>
</div>
<script>
let btnEstablecer = document.getElementById('establishList');
btnEstablecer.addEventListener('click', function() {
let minPric = parseInt(
document.getElementById('input_price-minList').value
);
let maxPric = parseInt(
document.getElementById('input_price-maxList').value
);
console.log(minPric, maxPric);
});
</script>
</body>
</html>
TA贡献1825条经验 获得超4个赞
你的代码片段有很多语法错误;我修复了它们但obj未定义:我不知道你想用这个实现什么
obj.map(obj => obj.Precio_cop > minPric && obj.Precio_cop < maxPric ?
elementosFilter.push(obj) : "");
键入错误,如按钮名称、输入元素 ID 使用空格 :|。
但我已经尝试修复您的代码,这是一个有效的代码片段
var btnEstablecer = document.getElementById("establishList");
btnEstablecer.addEventListener("click", function(){
let minPric = parseInt(document.getElementById("input_price-minList").value);
let maxPric = parseInt(document.getElementById("input_price-maxList").value);
console.log("Min price :" + minPric +" max price :"+ maxPric);
});
<div class="filter-price">
<input class="input_price-min" id="input_price-minList" type="value" placeholder="Mínimo">
<input class="input_price-max" id="input_price-maxList" type="value" placeholder="Máximo">
<button class="establish-button" id="establishList">Establecer</button>
</div>
添加回答
举报