使用innerHTML编写两个函数和文本
我不好意思问,但我需要帮助让这些脚本一起工作并输出我正在寻找的内容:
HEAD 部分,第一个脚本:
function copyToClipboard(s) {
if (window.clipboardData && clipboardData.setData) {
clipboardData.setData('text', s);
}
}
HEAD 部分,第二个脚本:
var name=prompt("Enter your first and last name please.","name");
function displayDate()
{
document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name + ";
}
BODY 部分:
<button type="button" onclick="displayDate()">Display Date</button>
<strong><a href="javascript: void(0)" id="copy" onclick="copyToClipboard(document.getElementById('time').innerHTML)"><span id="time">Date and time will display here</span></a></strong>
所以基本上我在这里想要完成的任务是一个网页,在页面加载时提示用户输入名字和姓氏。然后,当他们单击标记为“显示日期”的按钮时,标记为“时间”的范围应更改为如下所示:
由 John Doe 于 2099 年 1 月 1 日星期四 12:59:59 编辑
我当前脚本的方式是在页面加载时出现“未终止的字符串常量”错误。当我单击按钮时,出现“预期对象”错误。
有人可以提供任何建议吗?
I'm embarassed to ask but I need help getting these scripts to work together and output what I'm looking for:
HEAD section, first script:
function copyToClipboard(s) {
if (window.clipboardData && clipboardData.setData) {
clipboardData.setData('text', s);
}
}
HEAD section, second script:
var name=prompt("Enter your first and last name please.","name");
function displayDate()
{
document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name + ";
}
BODY section:
<button type="button" onclick="displayDate()">Display Date</button>
<strong><a href="javascript: void(0)" id="copy" onclick="copyToClipboard(document.getElementById('time').innerHTML)"><span id="time">Date and time will display here</span></a></strong>
So basically what I'm trying to accomplish here is a webpage that prompts the user to enter their first and last name when the page loads. Then when they click the button that's labeled "Display Date", the span labeled "time" should change to something like:
Edited on Thu Jan 01 12:59:59 2099 by John Doe
The way I have the current script is giving me a "Unterminated string constant" error when the page loads. When I click the button I get an "Object expected" error.
Can anyone provide any suggestions please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你确实有一个未终止的字符串。检查名称变量后。
You do have an unterminated string. Check after the name variable.