1

我正在使用一个具有多个步骤的表单,如果另一个类 .RegCurrent 包含文本“步骤 1 选择”,我想隐藏一段应用了 .newtest 类的文本。

<ol class="steps">
<li class="RegCurrent">Step 1 Selection</li>
<li class="notcurrent">Step 2 Selection</li>
<li class="notcurrent">Step 3 Selection</li>
</ol>

<div class="singleCol">
<span class="newtest">
<h1>some text</h1>
<p>some more text</p>
</span>
<p>some text and tables</p>
</div>

我试过的:

<script>
$(document).ready(function() {
if( $('.RegCurrent:contains("Step 1 Selection")') {
$('.newtest').hide();
}
});
</script>
4

2 回答 2

2

You have to use lengthwith selector in condition, other wise you wont get false as you will get jQuery object event when selector does not return any object. 您还错过了条件的右括号。

现场演示

$(document).ready(function() {
  if( $('.RegCurrent:contains("Step 1 Selection")').length) {
    $('.newtest').hide();
  }
});
于 2013-08-07T17:18:06.407 回答
0
if($('.RegCurrent').text() == "Step 1 Selection"){
    $('.newtest').hide();
}
于 2013-08-07T17:18:49.333 回答