这是获取状态类的所有ID的JavaScript代码。 我想获取类状态的所有输入值。 如何使用JavaScript获取印度类的所有州类?
function get_states(){
var category = document.formy.category.value;
var date_from = document.formy.date_from.value;
var date_to = document.formy.date_to.value;
var no_of_states = document.querySelectorAll(".states").length;
var from = Date.parse(date_from);
var to = Date.parse(date_to);
var state_name = ["karnataka", "maharashtra", "bihar"];
if (to > from) {
for (var i = 0; i <= state_name.length - 1; i++) {
document.write(state_name[i]);
document.write("<br>");
}
}
else
document.write('back');
}
我想获取类状态的所有输入ID值。
这是HTML:
<form action="search_content.php" method="post" name="formy">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<select class="custom-select" name="category" required="required">
<option value="0">Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</div>
<div class="col-md-3"><input type="date" name="date_from" required="required"></div>
<div class="col-md-3"><input type="date" name="date_to" required="required"></div>
<div class="col-md-3"><input type="submit" value="submit" onclick="get_states()"></div>
</div>
<div class="row">
<div class="india">
<div class="states" id="karnataka">
<input type="hidden" name="karnataka" value="2018-02-02">
<p>ABCD</p>
</div>
<div class="states" id="maharastra">
<input type="hidden" name="maharastra" value="2018-06-02">
<p>ABCD</p>
</div>
</div>
</div>
</form>
如何获取全状态输入值?请解释。
答案 0 :(得分:0)
您发布的HTML的格式没有那么难破解,但是在一般情况下,您可以这样做:
let ids = [];
let els = document.getElementsByClassName('state')
for (let i = 0; i < els.length; i++){
ids.push(els[i].id);
}