HTML文件路径引用困境

时间:2016-05-19 03:02:59

标签: php html twitter-bootstrap

<script type="text/javascript">
	var hoursleft = 0;
	/*get value from database*/
	var minutesleft = <?php echo $menit->alat_waktu ?>;
	var secondsleft = 0; 
	var finishedtext = "SELESAI";
	var end1;
	if(localStorage.getItem("end1")) 
	{
		end1 = new Date(localStorage.getItem("end1"));
	}
	else 
	{
		end1 = new Date();
		end1.setHours(end1.getHours()+hoursleft);
		end1.setMinutes(end1.getMinutes()+minutesleft);
		end1.setSeconds(end1.getSeconds()+secondsleft);
	}

var counter = function () {
	var now = new Date();
	var datediff = end1 - now;

	diff = new Date(datediff);

	var milliseconds = parseInt((diff%1000)/100)
    var sec = parseInt((diff/1000)%60)
    var mins = parseInt((diff/(1000*60))%60)
    var hours = parseInt((diff/(1000*60*60))%24);
	if(hours < 10) {
		hours = "0" + hours;
	}
	if (mins < 10) {
		mins = "0" + mins;
	}
	if (sec < 10) {
		sec = "0" + sec;
	}     
	if(now >= end1) {     
		clearTimeout(interval);
		localStorage.setItem("end1", null);
		localStorage.removeItem("end1");
		document.getElementById('divCounter').innerHTML = finishedtext;
		
		if(confirm("TIME OUT !!!"))
		clearInterval(counter);
		window.location.href= "http://localhost/psiko";
		document.getElementById('myform').submit();
	} else {
		var value = hours + ":" + mins + ":" + sec;
/*--------save variable value to db----------*/ 
/*save countdown timer when form is opened*/
 // document.myform.waktu_awal.value = end1;
/*save countdown timer when submit button is clicked*/
		document.myform.waktu_akhir.value = value;
/*------------------------------------------------*/
		localStorage.setItem("end1", end1);
		document.getElementById('divCounter').innerHTML = value; 
	}
}

var interval = setInterval(counter, 1000);
</script>

我正在进行的项目中有这个文件夹结构。并且最初考虑将 navbar 放在一个单独的文件中,以便在我拥有的所有其他文件中/index.php /navbar.php // <a id="#this"></a><div id="that"></div> /user/search.php /user/register.php 。但是当我在一个文件中include navbar.php而不是root中的任何文件时,相对路径将不起作用所以我现在使用绝对路径。 navbar.php实现了Bootstrap手风琴btw,我的问题是,我无法使它适用于我目前所有的文件路径问题。

我做错了什么?应该做什么?以及关于我如何构建文件的任何评论?请include的{​​{1}}对此事进行排序(阅读此atm)?

编辑:
navbar.php:

PHP

index.php:

include_path

user / search.php:

<div id="accordion">  
<ul class="nav nav-sidebar">  
    <li><a href="/index.php">HOME</a></li>  
    <li><a href="#search">SEARCH</a></li>  
    <li><a href="#register">REGISTER</a></li>  
</ul>  
<div class="collapse">
   <div id="search"> . . . </div>  
   <div id="register"> . . .</div>    
</div>  
</div>  

如果我对导航栏<?php include("navbar.php") ?> ...some <html> 使用相对路径,一切都很好但不在我<?php include("../navbar.php") ?> ...some <html> 文件夹内时 如果我使用绝对路径,idk,我怎样才能正确地实现它来定位特定的标签(在我的情况下,指向div的锚点)本身?

0 个答案:

没有答案