Platform
Resources
Pricing
Sign in
Get started
深度碎片
as simple as possible
Workspace
Fork
Published
By
深度碎片
Edited
Dec 14, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
html
`<p id="demo"></p>`
Insert cell
html
`<button onclick="document.getElementById('demo').innerHTML = Date()">The time is?</button>`
Insert cell
Insert cell
html
`<button onclick="this.innerHTML = Date()">The time is?</button>`
Insert cell
html
`<button onclick="this.innerHTML = Date(); this.innerHTML += 'date'">The time is?</button>`
Insert cell
Insert cell
html
`<button onclick="displayDate()">The time is?</button>`
// cell 1 (it won't work as it is not a global in the notebook)
Insert cell
html
`<button onclick="${
displayDate
(
)
}">The time is?</button>`
// cell 2 (Mike is going to make this work soon)
Insert cell
demo1
=
html
`<p id="demo1"></p>`
// with a name, this cell can be put forward
Insert cell
solution1
=
Object
.
assign
(
html
`<button>The time is?</button>`
,
{
onclick
:
displayDate
}
)
Insert cell
solution2
=
{
const
button
=
html
`<button>The time is?</button>`
;
button
.
addEventListener
(
"click"
,
displayDate
)
;
return
button
;
}
Insert cell
solution3
=
html
`<button onclick=${
displayDate
}>The time is?</button>`
// the new html make it work
Insert cell
function
displayDate
(
)
{
return
document
.
getElementById
(
"demo1"
)
.
innerHTML
=
new
Date
(
)
.
toLocaleTimeString
(
)
;
}
// not working
Insert cell
Insert cell
viewof
update
=
html
`<button>Update the time`
Insert cell
{
update
;
return
new
Date
(
)
.
toLocaleTimeString
(
)
;
}
Insert cell
Insert cell
import
{
html
,
svg
}
from
"@observablehq/htl"
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
option
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
problem
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
demo1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
solution1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
solution2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
solution3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
displayDate
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
update
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML