在特定页面上隐藏div

时间:2017-06-20 17:54:25

标签: javascript html

所以我有3个选择选项框。我希望在某个页面上隐藏第三个。出于某种原因,我的代码不起作用。我做错了什么?

HTML:

<div class="form-group">
<label class="col-md-4 control-label">First:</label>
<div class="col-md-8">
<select id="first" class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
 </select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Second:</label>
<div class="col-md-8">
<select id="second" class="form-control">
  <option>4</option>
  <option>5</option>
  <option>6</option>
 </select>
</div>
</div>
<div class="form-group">
<label id="thirdid" class="col-md-4 control-label">Third:</label>
<div class="col-md-8">
<select id="third" class="form-control">
  <option>7</option>
  <option>8</option>
  <option>9</option>
 </select>
</div>

脚本:

 if (top.location.pathname === '/ajax/test/yes.html')
                {
                    $("#third").hide();
                    $("#thirdid").hide();
                }

2 个答案:

答案 0 :(得分:1)

我相信

if (window.location.pathname === '/ajax/test/yes.html') { }

会奏效。直接从here获取,您可以找到这样的网址:

var newURL = window.location.protocol + "//" + window.location.host + window.location.pathname;

答案 1 :(得分:0)

这应该有效

   $(function(){
          if (window.location.pathname == "/ajax/test/yes.html") {
              $("#third").hide();
              $("#thirdid").hide();
          } 
     });