Javascript 在Window.onKeyDown之后在HTML模板上创建文本
更新0 获取此错误消息:未定义UncaughtReferenceError:$ 更新0 更新1个最新来源Javascript 在Window.onKeyDown之后在HTML模板上创建文本,javascript,html,Javascript,Html,更新0 获取此错误消息:未定义UncaughtReferenceError:$ 更新0 更新1个最新来源 <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Reservations</title> <link rel="stylesheet" href="/stati
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Reservations</title>
<link rel="stylesheet" href="/static/css/main.css">
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<center><h1>Reservations</h1></center>
<div class="wrapper">
<p> You can start over at the beginning <a href="/">here.</a> </p>
<big>Reserve some courts online </big> <br />
<script type="text/javascript" language="JavaScript">
$( document ).keypress(function() {
$("#timeStamp span").text("Timestamp is no-longer correct");
});
</script>
<form action="" method="post" >
<input type="hidden" name="ID" value="Rogers"></input>
<input type="hidden" name="weekday" value="Tuesday"></input>
<input type="hidden" name="nowweekday" value="1"></input>
<input type="hidden" name="month" value="September"></input>
<input type="hidden" name="nowmonth" value="9"></input>
<input type="hidden" name="day" value="18"></input>
<input type="hidden" name="year" value="2012"></input>
<input type="hidden" name="startTime" value="[15, 0]"></input>
<input type="hidden" name="endTime" value="[20L, 0L]"></input>
<input type="hidden" name="court" value="court1"></input>
<input type="hidden" name="court" value="court2"></input>
<h1>Tuesday, September 18, 2012 at Rogers Neighborhood Club</h1>
<div class="timeStamp" ><h1 id="timeStamp">15:07:24.657430<span></span></h1></div> <br />
是的,像这样:
假设您使用的是jQuery,并且时间戳为HTML,如下所示:
<p id="timeStamp">2012-09-18 20:08 <span></span></p>
<!-- the span is where the message will be inserted -->
更改身体元素如下:
。。。每次按键时,它都会执行按键功能。在那里做你想做的一切 你能分享你的代码吗?那么你想听听文档中任何元素的keyDown
?您当前使用的javascript库是什么?您可以在主体上附加keydown事件,很可能是fasterI添加的以下代码<代码>{{tod}}在中,但网页在
之前停止在浏览器中打印。{…}是因为我使用的是jinja2。请将生成的相关标记(不是源代码)发布到原始问题。对不起,我不知道怎么做。我刚刚了解到Chrome的html开发者控制台。如果你需要的是在那里的某个地方,请描述在哪里,因为我在默认窗口中看到的是最小的。另外,请注意,我之前的评论中有一个输入错误:
应该是Chrome中的,找到页面的源代码,然后通过单击编辑按钮将其复制并粘贴到原始问题中。不,不,内联javascript在这里没有用。。。有很多方法可以被覆盖。只有在绝对需要时才使用内联javascript。我使用的是jinja2功能,其中base.html包含一个包装器`Reservations{%block content%}{%endblock content%}`扩展了我的所有其他页面,因此标记不在这个特定页面中。
<p id="timeStamp">2012-09-18 20:08 <span></span></p>
<!-- the span is where the message will be inserted -->
$( document ).keypress(function() {
$("#timeStamp span").text("Timestamp is no-longer correct");
});