所以我有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();
}
最佳答案
我相信
if (window.location.pathname === '/ajax/test/yes.html') { }
将工作。直接从here获取,您可以找到如下所示的URL部分:
var newURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
关于javascript - 在特定页面上隐藏div,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44659958/