使用innerHTML编写两个函数和文本

发布于 2024-12-01 18:46:34 字数 1050 浏览 2 评论 0原文

我不好意思问,但我需要帮助让这些脚本一起工作并输出我正在寻找的内容:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里人 2024-12-08 18:46:34
function displayDate()
{
   document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name + ";
}

你确实有一个未终止的字符串。检查名称变量后。

function displayDate()
{
   document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name + ";
}

You do have an unterminated string. Check after the name variable.

回忆那么伤 2024-12-08 18:46:34
var name=prompt("Enter your first and last name please.","name");

function displayDate()
{
document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name;
}
var name=prompt("Enter your first and last name please.","name");

function displayDate()
{
document.getElementById("time").innerHTML="Edited on " + Date() + " by " + name;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文