我想隱藏特定的文本後,某些要素的第一個divjQuery的 - 隱藏視字後具體的文本元素
<div class="top">here is some text</div>
<table class="middle">
...
</table>
<div class="bottom">...</div>
隱藏目錄(中)和DIV(底部)/硬道理「文本」從第一個div
我想隱藏特定的文本後,某些要素的第一個divjQuery的 - 隱藏視字後具體的文本元素
<div class="top">here is some text</div>
<table class="middle">
...
</table>
<div class="bottom">...</div>
隱藏目錄(中)和DIV(底部)/硬道理「文本」從第一個div
嘗試
txtWord = $('.top').text().split('text')[1]
if(txtWord){
alert("div show");
}else{
alert("div hide");
}
[1]代表什麼? – Jim 2013-05-14 13:14:05
之後形成「文字」 – ShibinRagh 2013-05-15 04:49:04
來源http://www.minihowtos.net/jquery-split – ShibinRagh 2013-05-15 04:49:43
例子,如果你的.TOP DIV文字隱藏或顯示功能必須是:
var txt = $('.top').text();
if(txt=='hide')
{
$('.middle').hide();
$('.bottom').hide();
}
else if(txt=='show')
{
$('.middle').show();
$('.bottom').show();
}
如果您需要檢查的第一個div的文本並顯示相對div
if($(".top").html() == "what you want")
{
$(".middle").show();
$(".bottom").hide();
}
else
{
$(".bottom").show();
$(".middle").hide();
}
var lastWord = function (o) {
return ("" + o).replace(/[\s-]+$/, '').split(/[\s-]/).pop();
};
if (lastWord($('.top').html()) === "mykeyword") {
$('.middle,.bottom').hide();
} else $('.middle,.bottom').show();
讓有你打電話
hideOrShow(){
if(document.getElementsByClassName('top')[0].innerHtml=="the text you want"){
document.getElementsByClassName('middle')[0].style.display='none';
document.getElementsByClassName('bottom')[0].style.display='none';
}else{
document.getElementsByClassName('middle')[0].style.display='block';
document.getElementsByClassName('bottom')[0].style.display='block';
}
}
的方法,你可以得到使用的最後一個字:$('.top').text().split(' ').pop()
,再添加一些簡單的邏輯來show/hide
其他元素:
var lastWord = $('.top').text().split(' ').pop();
$('.middle, .bottom').toggle(lastWord == 'text');
你覺得你的問題比較清楚......? – 2013-05-14 12:39:15
* ...和div取決於「文本」*。你的意思是什麼'div'? – VisioN 2013-05-14 12:39:21
希望這可以幫助你,http://stackoverflow.com/questions/1854493/jquery-search-to-any-string – dreamweiver 2013-05-14 12:40:49