[英]javascript querySelectorAll() - how to
我有這個代碼。 即使在聲明之后
curr_attr.value = 'display: block' ;
執行后,面板不可見。 但是,它第二次可以正常工作,它在工作和不工作之間交替。
function filterEntries() {
var selectedText = $("#search :selected").text();
var enteredText = $("#txtSearchValue").val();
enteredText = enteredText.split(" ").join("");
var table;
var allPanels = $(".panel");
console.log("allPanels.hide(2000); at line number 202");
allPanels.hide(1000);
if (selectedText.toLowerCase() === 'band name') {
if (enteredText === '') {
// remove filter and show all elements
console.log("allPanels.show(); at line number 210");
allPanels.show(1000);
} else {
//console.log("allPanels.show(); at line number 215");
//allPanels.show(1000);
table = document.querySelectorAll("[data-searchband=" + CSS.escape(enteredText) + "]");
for (var i = 0; i < table.length; ++i) {
// print the tag name of the node (DIV, SPAN, etc.)
var curr_node = table[i];
console.log(curr_node.tagName);
// show all the attributes of the node (id, class, etc.)
for (var j = 0; j < curr_node.attributes.length; ++j) {
var curr_attr = curr_node.attributes[j];
console.log(curr_attr.name, curr_attr.value);
if (curr_attr.name === 'style') {
curr_attr.value = 'display: block' ;
}
}
}
}
else {
alert("Please select a search criteria");
}
}
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<select id="search" class="navbar-inverse small" name="search" onchange="searchFilters()">
<option value="-1">Search Criteria</option>
<option value="band">Band Name</option>
<option value="title">Content Title</option>
</select>
<input type="text" class="small" id="txtSearchValue" placeholder="Search for...">
<span id="btnSearch" onclick="filterEntries()" class="btn btn-default btn-sm">Search</span>
</div>
</div>
問題在於捉迷藏。 我曾經使用hide(2000)和show()。 將hide(2000)替換為hide()后,它開始工作。 我猜該動畫弄亂了show()或display = block。 現在,用hide()代替hide(2000)時,display =塊可以完美工作。 謝謝大家!
您可以使用curr_node.style.display = 'block'
。
例如,輸入控制台document.body.style.display = 'none'
並查看效果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.