在下面的代码中,我试图输出您输入的日期和打印文本。日期时间按其显示的方式工作,但是当我实现打印功能时,它输出“ime”。
当您键入“打印”以及之后的其他内容时,打印功能就会起作用。例如,输入“print hi there”输出“hi there”。任何反馈将不胜感激。
<html>
<body>
<div id="out" name="out"></div>
<script type="text/JavaScript">
function theProcess(){
alert("> Your typed "+enter);
}
function datetime(){
var enter = "";
var currentdate = new Date();
var datetime = "Date and Time today: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
if (enter == 'datetime')
{
alert(datetime)
}
else
{
alert(" You typed, "+enter);
}
}
</script>
<script type="text/JavaScript">
function addOutput(s){
document.getElementById("out").innerHTML=document.getElementById("out").innerHTML+s+"\n";
}
// turns a string into an array and displays it
var enter = '';
enter = prompt('enter text')
var str = "print a b c d";
var list = str.split(" ");
for(i=0; i<list.length;i++){
var message=list[i];
switch(message){
case "print":
alert(message.substring(5))
}
}
</script>
</body>
</html>