包括在html中创建的javascript文件

时间:2016-05-06 07:10:01

标签: javascript jquery html

不知何故,我无法创建外部JavaScript文件。如果我从其他示例中导入它们,它们可以正常工作,但如果是我创建并导入它们的文件,它们就无法工作。如果我将它们包含在HTML中,它们工作正常但如果我引用它们它们就不起作用。我不知道自己做错了什么。

这是我的HTML:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Documento sem título</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="jquery.js" type="text/javascript"></script>
        <script src="jquery.ui.draggable.js" type="text/javascript"></script>

        <!-- Core files -->
        <script src="jquery.alerts.js" type="text/javascript"></script>

<body>
<script type="text/javascript" src="horario.js"></script>


    <div id="entrada">
    <input id="time" class="inputs" type="text" maxlength="2"></input>
    <input id="time2" class="inputs" type="text" maxlength="2"></input>
    <button class="inputs" id="confirm_button" class="inputs1" onKeyPress="localStore()" onClick="localStore()">entrada</button>
    </div>


    <div id="result"></div>
    <div id="millsentr"></div>
    <div id="millssai"></div>


    <div id="mills"></div>
    <div id="totHoras"></div>



</body>
</html>

这是javascript文件:

$(".inputs").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).next('.inputs').focus();
}
});
$(".inputs1").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).next('.inputs').focus();
}
});


$(document).ready( function() {

$("#confirm_button").click( function() {
jConfirm('Can you confirm this? ', 'Confirmation Dialog', function(r) {

var entradasaida = 0;

entradasaida = localStorage.getItem("entradasaida");
if(r == true){

if(entradasaida == 0){
var time = $('#time').val();
var time2 = $('#time2').val();
var datetime = new Date();

var year = datetime.getFullYear();
var month = datetime.getMonth()+1;
if(month < 10){
month = "0"+month
}
var day = datetime.getDay()+1;
if(day < 10){
day = "0"+day
}
var date = new Date(year+"-"+month+"-"+day+" "+time+":"+time2); 

var mills = date.getTime();

localStorage.setItem("horas", time);
localStorage.setItem("mins", time2);
localStorage.setItem("entradasaida",1);
localStorage.setItem("millsEnt",mills);
$('#confirm_button').text("Saida");
$('#time, #time2').val("");
$('#millsentr').text(mills);

} else{

var horasEnt = localStorage.getItem("horas");
var minsEnt = localStorage.getItem("mins");
var entrada = localStorage.getItem("millsEnt");

localStorage.setItem("entradasaida",0);
$('#confirm_button').text("Entrada");

var time = $('#time').val();
var time2 = $('#time2').val();
var datetime = new Date();

var year = datetime.getFullYear();
var month = datetime.getMonth()+1;
if(month < 10){
month = "0"+month
}
var day = datetime.getDay()+1;
if(day < 10){
day = "0"+day
}
var date1 = new Date(year+"-"+month+"-"+day+" "+time+":"+time2); 


var millssai = date1.getTime();
$('#millssai').text(millssai);

var totMills = (millssai - entrada)

var horas = time - horasEnt;
var mins = time2 - minsEnt;
if(mins < 0){
mins = mins*(-1);
horas = horas-1;
}
var totHoras = horas+":"+mins
$('#totHoras').text(totHoras);
$('#mills').text(totMills);
$('#time, #time2').val("");
}   

}   else{r == false}                

    });
});
});

在这里,horario.js是我创建的文件并且无法正常工作,我在示例中使用的其他脚本文件工作正常。

0 个答案:

没有答案