已经有几个SO解决方案,但我没有运气让他们工作.JQuery初学者试图通过一个解决方案在一个简单的导航菜单中将"活动"类添加到活动列表项:
<div id="main-menu">
<ul>
<li><a href="/site/about">About Us</a></li>
<li><a href="/site/work">Our Work</a></li>
<li><a href="/site/contact">Contact Us</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
之前的SO帖子表明这有效,但到目前为止我没有成功.我在wordpress中使用非常永久链接,因此任何页面的完整路径如下:
http://www.foobar.com/site/about/
到目前为止,这是我的工作:
<script>
$(function(){
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,''));
$('#main-menu li').each(function(){
if(urlRegExp.test(this.href)){
$(this).addClass('active');
}
});
});?
</script>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几种解决方案,包括改变我写href的方式等等.我真正模糊的代码部分是urlRegExp部分......有什么帮助吗?
我刚刚开始我的PHP旅程,并正在完成创建简单日历的教程.我在Codepad中遇到语法错误,但无法找到修复程序.我确信这是我看不到的简单事.对于这些笔记感到抱歉,我一直试图尽可能地注释,所以我不会迷路.
错误是:
Parse error: syntax error, unexpected ',' on line 10. (the $day=('d', $date) declaration)
Run Code Online (Sandbox Code Playgroud)
码:
<?php
// current date variable
$date = time ();
//day, month and year variables
$day = ('d', $date);
$month = ('m', $date);
$year = ('Y', $date);
// first day of the month
$monthfirstday = mktime(0,0,0,$month, 1, $year);
// get the name of the month
$monthtitle = ('F', $monthfirstday);
// first day of the week
$weekday = ('D', $monthfirstday);
// identify the days of the …Run Code Online (Sandbox Code Playgroud)