在输入匡无法读取到javascript时间
<%@ page language="java" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
%>
<html lang="en">
<head>
<link rel="stylesheet" href="css/jquery-ui.css">
<script src="js/jquery-1.11.2.js"></script>
<script src="js/jquery-ui.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" media="(max-width: 640px)" href="max-640px.css">
<link rel="stylesheet" href="plug-in/bootstrap/css/bootstrap.css" type="text/css"></link>
<div id="名称">
<script language=Javascript>
// var now = new Date()
// document.write(1900 + now.getYear() + "-" + (now.getMonth() + 1) + "-"
// + now.getDate() + " " + now.getHours() + ":" + now.getMinutes()
// + ":" + now.getSeconds())
// var d = new Date();
// document.write("现在是:" + d.toLocaleString());
//假设文本框1和3必须输入
//focusin事件为光标进入,focusout为光标离开
$("#devicenumber").focusin(function () {
$("#Text1Note").html("文本框1该项必须填写!");
}).focusout(function () {
if ($("#Text1").val() == "")
$("#Text1Note").html("文本框1该项必须填写!");
else
$("#Text1Note").html("");
});
$("#Text3").focusin(function () {
$("#Text3Note").html("文本框3该项必须填写!");
}).focusout(function () {
if ($("#Text3").val() == "")
$("#Text3Note").html("文本框3该项必须填写!");
else
$("#Text3Note").html("");
});
//不做任何输入直接提交执行提交执行
function onsumbit() {
if ($("#Text1").val() == "")
$("#Text1Note").html("文本框1该项必须填写!");
if ($("#Text3").val() == "")
$("#Text3Note").html("文本框3该项必须填写!");
return false;
}
function checkReset() {
if (!confirm("确认重置表单吗?")) {
return false;
}
}
function ShowTime() {
var NowDate = new Date();
var year = NowDate.getFullYear();
var month = (NowDate.getMonth() + 1);
var day = NowDate.getDate();
var h = NowDate.getHours();
var m = NowDate.getMinutes();
var s = NowDate.getSeconds();
document.getElementById('showbox').innerHTML = year + '年' + month
+ '月' + day + '日' + h + '時' + m + '分' + s + '秒';
setTimeout('ShowTime()', 1000);
}
function getDate(my) {
var date = new Date();
var dates = date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
+ date.getDate() + " " + date.getHours() + ":"
+ date.getMinutes()+":"+date.getSeconds();
my.value = dates.toLocaleString();
}
//-----------------------------下拉提示-----------------------------------//
$(function() {
$('#tags').keypress(function () {
$.ajax({
url:"Auto",
type:"post",
data:'',
success:function(data){
$( "#tags" ).autocomplete({
source: data
});
},error: function(data, status, er){
console.log(data+"_"+status+"_"+er);
},
});
});
});
//-----------------------------下拉提示2-----------------------------------//
var xmlHttp;
//创建XMLHttpRequest对象
function createXmlHttp() {
//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
if (window.XMLHttpRequest) {
//FireFox、Opera等浏览器支持的创建方式
xmlHttp = new XMLHttpRequest();
} else {
//IE浏览器支持的创建方式
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function inputSuggest() {
var txtValue = document.getElementById('txt').value;
createXmlHttp();
xmlHttp.onreadystatechange = _handle;
url = "suggest.do?txtValue=" + txtValue;
xmlHttp.open("POST", url, false);
xmlHttp.send(null);
}
function _handle() {
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var str = xmlHttp.responseText.split("#");
var s = document.getElementById('result_display')
s.innerHTML = '';
for(i=0; i < str.length - 1; i++) {
var suggest = '<div onmouseover="onmouseOver(this);" ';
suggest += 'onmouseout="onmousetOut(this);" ';
suggest += 'onclick="setSuggestValue(this.innerHTML);" ';
suggest += 'class="onmouset_out">' + str[i] + '</div>';
s.innerHTML += suggest;
}
}
}
}
function onmouseOver(div) {
div.className = 'onmouse_over';
}
function onmousetOut(div) {
div.className = 'onmouset_out';
}
function setSuggestValue(value) {
document.getElementById('txt').value = value;
document.getElementById('result_display').innerHTML = '';
}
</script>
</div>
<body onload="ShowTime()">
<div id="showbox"></div>
</body>
<style type="text/css" media="screen">
.shadow,.one,.two,.three,.four,.five,.six {
height:50px;
width:280px;
border:1px solid #CCC;
}
.shadow {
-moz-box-shadow: inset 0 0 10px #CCC;
-webkit-box-shadow: inset 0 0 10px #CCC;
box-shadow: inset 0 0 10px #CCC;}
.one {
-moz-box-shadow:5px 5px;
-webkit-box-shadow:5px 5px;
box-shadow:5px 5px;
}
.two {
-moz-box-shadow:2px 2px 10px #06c;
-webkit-box-shadow:2px 2px 10px #06c;
box-shadow:2px 2px 10px #06c;
}
.three {
-moz-box-shadow:0 0 10px #06c;
-webkit-box-shadow:0 0 10px #06c;
box-shadow:0 0 10px #06c;
}
.four {
-moz-box-shadow:0 0 10px 10px #06c;
-webkit-box-shadow:0 0 10px 10px #06c;
box-shadow:00 10px 10px #06c;
}
.five {
-moz-box-shadow:inset 5px 5px 10px #06c;
-webkit-box-shadow: inset 5px 5px 10px #06c;
box-shadow:inset 5px 5px 10px #06c;
}
.six {
-moz-box-shadow:0 0 10px red,
2px 2px 10px 10px yellow,
4px 4px 12px 12px green;
-webkit-box-shadow:0 0 10px red,
2px 2px 10px 10px yellow,
4px 4px 12px 12px green;
box-shadow:00 10px red,
2px 2px 10px 10px yellow,
4px 4px 12px 12px green;
}
.onmouset_out {
background-color: #99CCFF;
padding: 2px 6px 2px 6px;
}
.onmouset_over {
background-color: #006600;
padding: 2px 6px 2px 6px;
}
#result_display {
border: 1px solid #FFFFFF;
}
p.demo {
color: white;
background-color: black;
}
@media only screen and (min-width:640px) {
.logo-2 {
display: none
}
}
@media only screen and (max-width:639px) {
.logo-1 {
display: none
}
}
</style>
</head>
<body>
<p>
<%
out.write("");
%>
</p>
<form action="mysql_insert.jsp" method="post" align=center
onreset="return checkReset();" id="frmSearch" >
<label class="logo-2" style="font-size:30px;"> 设备编号 : </label> <input
type="text" name="device_code" id="devicenumber" value=" "
style="font-size:30px;height: 65px; width: 269px; "
onfocus="this.value=''" class="shadow" /><span id="Text1Note"></span> <br> <br> <label class="logo-2"
style="font-size:30px;"> 产品型号 : </label><input type="text"
name="product_model" value=" "
style="font-size:30px;height: 65px; width: 269px; "
onfocus="this.value=''" id="txt" onkeyup="inputSuggest();" class="shadow"/>
<br> <br> <label class="logo-2"
style="font-size:30px;"> 生产批号: </label><input type="text"
name="batch_no" value=" "
style="font-size:30px;height: 65px; width: 269px; "
onfocus="this.value=''" class="shadow" /> <br> <br> <label class="logo-2"
style="font-size:30px;">創建時間 : </label>
<input type="text" comboname="time" name="registe_date" value=""
onload="getDate(this);"
" class="shadow"
style="font-size:30px;height:65px; width: 269px;" /> </br> <br>
<input type="submit" value="提交" /> <input type="reset" value="重置表单" />
</form>
</body>
<%@ page contentType="text/html;charset=utf-8"%>
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
%>
<html lang="en">
<head>
<link rel="stylesheet" href="css/jquery-ui.css">
<script src="js/jquery-1.11.2.js"></script>
<script src="js/jquery-ui.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" media="(max-width: 640px)" href="max-640px.css">
<link rel="stylesheet" href="plug-in/bootstrap/css/bootstrap.css" type="text/css"></link>
<div id="名称">
<script language=Javascript>
// var now = new Date()
// document.write(1900 + now.getYear() + "-" + (now.getMonth() + 1) + "-"
// + now.getDate() + " " + now.getHours() + ":" + now.getMinutes()
// + ":" + now.getSeconds())
// var d = new Date();
// document.write("现在是:" + d.toLocaleString());
//假设文本框1和3必须输入
//focusin事件为光标进入,focusout为光标离开
$("#devicenumber").focusin(function () {
$("#Text1Note").html("文本框1该项必须填写!");
}).focusout(function () {
if ($("#Text1").val() == "")
$("#Text1Note").html("文本框1该项必须填写!");
else
$("#Text1Note").html("");
});
$("#Text3").focusin(function () {
$("#Text3Note").html("文本框3该项必须填写!");
}).focusout(function () {
if ($("#Text3").val() == "")
$("#Text3Note").html("文本框3该项必须填写!");
else
$("#Text3Note").html("");
});
//不做任何输入直接提交执行提交执行
function onsumbit() {
if ($("#Text1").val() == "")
$("#Text1Note").html("文本框1该项必须填写!");
if ($("#Text3").val() == "")
$("#Text3Note").html("文本框3该项必须填写!");
return false;
}
function checkReset() {
if (!confirm("确认重置表单吗?")) {
return false;
}
}
function ShowTime() {
var NowDate = new Date();
var year = NowDate.getFullYear();
var month = (NowDate.getMonth() + 1);
var day = NowDate.getDate();
var h = NowDate.getHours();
var m = NowDate.getMinutes();
var s = NowDate.getSeconds();
document.getElementById('showbox').innerHTML = year + '年' + month
+ '月' + day + '日' + h + '時' + m + '分' + s + '秒';
setTimeout('ShowTime()', 1000);
}
function getDate(my) {
var date = new Date();
var dates = date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
+ date.getDate() + " " + date.getHours() + ":"
+ date.getMinutes()+":"+date.getSeconds();
my.value = dates.toLocaleString();
}
//-----------------------------下拉提示-----------------------------------//
$(function() {
$('#tags').keypress(function () {
$.ajax({
url:"Auto",
type:"post",
data:'',
success:function(data){
$( "#tags" ).autocomplete({
source: data
});
},error: function(data, status, er){
console.log(data+"_"+status+"_"+er);
},
});
});
});
//-----------------------------下拉提示2-----------------------------------//
var xmlHttp;
//创建XMLHttpRequest对象
function createXmlHttp() {
//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
if (window.XMLHttpRequest) {
//FireFox、Opera等浏览器支持的创建方式
xmlHttp = new XMLHttpRequest();
} else {
//IE浏览器支持的创建方式
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function inputSuggest() {
var txtValue = document.getElementById('txt').value;
createXmlHttp();
xmlHttp.onreadystatechange = _handle;
url = "suggest.do?txtValue=" + txtValue;
xmlHttp.open("POST", url, false);
xmlHttp.send(null);
}
function _handle() {
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var str = xmlHttp.responseText.split("#");
var s = document.getElementById('result_display')
s.innerHTML = '';
for(i=0; i < str.length - 1; i++) {
var suggest = '<div onmouseover="onmouseOver(this);" ';
suggest += 'onmouseout="onmousetOut(this);" ';
suggest += 'onclick="setSuggestValue(this.innerHTML);" ';
suggest += 'class="onmouset_out">' + str[i] + '</div>';
s.innerHTML += suggest;
}
}
}
}
function onmouseOver(div) {
div.className = 'onmouse_over';
}
function onmousetOut(div) {
div.className = 'onmouset_out';
}
function setSuggestValue(value) {
document.getElementById('txt').value = value;
document.getElementById('result_display').innerHTML = '';
}
</script>
</div>
<body onload="ShowTime()">
<div id="showbox"></div>
</body>
<style type="text/css" media="screen">
.shadow,.one,.two,.three,.four,.five,.six {
height:50px;
width:280px;
border:1px solid #CCC;
}
.shadow {
-moz-box-shadow: inset 0 0 10px #CCC;
-webkit-box-shadow: inset 0 0 10px #CCC;
box-shadow: inset 0 0 10px #CCC;}
.one {
-moz-box-shadow:5px 5px;
-webkit-box-shadow:5px 5px;
box-shadow:5px 5px;
}
.two {
-moz-box-shadow:2px 2px 10px #06c;
-webkit-box-shadow:2px 2px 10px #06c;
box-shadow:2px 2px 10px #06c;
}
.three {
-moz-box-shadow:0 0 10px #06c;
-webkit-box-shadow:0 0 10px #06c;
box-shadow:0 0 10px #06c;
}
.four {
-moz-box-shadow:0 0 10px 10px #06c;
-webkit-box-shadow:0 0 10px 10px #06c;
box-shadow:00 10px 10px #06c;
}
.five {
-moz-box-shadow:inset 5px 5px 10px #06c;
-webkit-box-shadow: inset 5px 5px 10px #06c;
box-shadow:inset 5px 5px 10px #06c;
}
.six {
-moz-box-shadow:0 0 10px red,
2px 2px 10px 10px yellow,
4px 4px 12px 12px green;
-webkit-box-shadow:0 0 10px red,
2px 2px 10px 10px yellow,
4px 4px 12px 12px green;
box-shadow:00 10px red,
2px 2px 10px 10px yellow,
4px 4px 12px 12px green;
}
.onmouset_out {
background-color: #99CCFF;
padding: 2px 6px 2px 6px;
}
.onmouset_over {
background-color: #006600;
padding: 2px 6px 2px 6px;
}
#result_display {
border: 1px solid #FFFFFF;
}
p.demo {
color: white;
background-color: black;
}
@media only screen and (min-width:640px) {
.logo-2 {
display: none
}
}
@media only screen and (max-width:639px) {
.logo-1 {
display: none
}
}
</style>
</head>
<body>
<p>
<%
out.write("");
%>
</p>
<form action="mysql_insert.jsp" method="post" align=center
onreset="return checkReset();" id="frmSearch" >
<label class="logo-2" style="font-size:30px;"> 设备编号 : </label> <input
type="text" name="device_code" id="devicenumber" value=" "
style="font-size:30px;height: 65px; width: 269px; "
onfocus="this.value=''" class="shadow" /><span id="Text1Note"></span> <br> <br> <label class="logo-2"
style="font-size:30px;"> 产品型号 : </label><input type="text"
name="product_model" value=" "
style="font-size:30px;height: 65px; width: 269px; "
onfocus="this.value=''" id="txt" onkeyup="inputSuggest();" class="shadow"/>
<br> <br> <label class="logo-2"
style="font-size:30px;"> 生产批号: </label><input type="text"
name="batch_no" value=" "
style="font-size:30px;height: 65px; width: 269px; "
onfocus="this.value=''" class="shadow" /> <br> <br> <label class="logo-2"
style="font-size:30px;">創建時間 : </label>
<input type="text" comboname="time" name="registe_date" value=""
onload="getDate(this);"
" class="shadow"
style="font-size:30px;height:65px; width: 269px;" /> </br> <br>
<input type="submit" value="提交" /> <input type="reset" value="重置表单" />
</form>
</body>
</html>
在输入匡无法读取到javascript方法,我想在输入匡中读取时间,但是我用onclick的时后可以,点的时后页面会显示,但是换成onload就没反应~请问有人知道怎么解决吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$(document).ready(
function() {
var date = new Date();
var year = date.getFullYear();
var month = (date.getMonth() + 1);
var day = date.getDate();
var hours = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var dates = Appendzero(year) + "-" + Appendzero(month)
+ "-" + Appendzero(day) + " " + Appendzero(hours)
+ ":" + Appendzero(min) + ":" + Appendzero(sec);
$("#registerTimeInput").val(dates.toLocaleString());
});
用jquery解决得~