我正在尝试根据 url 传递一个类。目前,2 个 for 循环一直在执行。有没有办法把它写得更干净,以避免执行任何不必要的代码?
const arrCommon = ['foo1', 'foo2', 'foo3', 'foo4'];
const arrOther = ['bar1', 'bar2', 'bar3'];
const activeUrl = window.location.href;
const activePage = activeUrl.substring(activeUrl.lastIndexOf('/') + 1);
for(let i=0; i<arrCommon.length; i++) {
if (activePage == arrCommon[i])
//if 'foo1, foo2 foo3 or foo4' add class to element 1
}
for(let i=0; i<arrOther.length; i++) {
if (activePage == arrOther[i]) {
//if 'bar1' add class to element 2
//if 'bar2' add class to element 3
//...
}
}
Run Code Online (Sandbox Code Playgroud) 这似乎是一个常见的问题,但我已经尝试了许多答案,但没有一个对我有用.
我正在使用jquery UI datepicker.有些东西似乎是错的.这就是我的看法.

我已将以下内容包含在我的文件中
我也尝试了下面的CSS但没有奏效.
.ui-datepicker {
background: #fff !important;
z-index: 10000;
}
Run Code Online (Sandbox Code Playgroud)
我怎样让它看起来很正常?
这可能是一个非常简单的问题,但我发现它令人困惑.
如果textField_1不为空,我如何运行myFunc()?
.on('click', '#openButton', myFunc)如果是激动人心的($('#textField_1').val()!="")?
如何使用另一个隐藏元素的宽度和高度设置隐藏元素的宽度和高度?
for(i=1;i<10;i++){
$('#hiddenE1'+i).width($('#hiddenE2'+i).width()).height($('#hiddenE2'+i).height());
}
Run Code Online (Sandbox Code Playgroud) 我正在使用bootstraps导航栏.当用户点击导航栏按钮时,导航栏保持打开状态.如何在单击导航栏按钮时折叠导航栏?
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a data-toggle="tab" href="#sectionA">Page1</a></li>
<li><a data-toggle="tab" href="#sectionB">Page2</a></li>
<li><a data-toggle="tab" href="#sectionC">Page3</a></li>
</ul>
</div>
</div>
</nav>
Run Code Online (Sandbox Code Playgroud)
截图:
这是单击导航栏按钮后的方式(菜单保持打开状态):

这是我在点击导航栏按钮(返回原始状态)后想要的样子:

我需要检查<form>中是否有空白输入文本字段.而不是多次这样做
$.trim($('#myMessage').val()) == '' || $.trim($('#myage').val()) == '' .//so on...
Run Code Online (Sandbox Code Playgroud)
检查多个空白文本字段的最佳方法是什么?
是否有可能将jQuery ajax响应转换为多个DIV?
我想在不同的DIV中分发回复.
HTML
<div id="postrequest1"></div>
<div id="postrequest2"></div>
Run Code Online (Sandbox Code Playgroud)
JQ
$(document).ready(function() {
$("#loaddata").click(function(){
$.post("php/test2.php",
{ name:$("#txtinput").val(),
location:$("#txtlocation").val() },
function(response) {
$("#postrequest").html(response);
});
});
});
Run Code Online (Sandbox Code Playgroud)
PH值:
$post_name=$_POST["name"];
$post_location=$_POST["location"];
if( $post_name && $post_location){
echo "Name: ". $post_name; // this should be displayed in postrequest1
echo "Location: " .$post_location; // this should be displayed in postrequest2
}
Run Code Online (Sandbox Code Playgroud)