我不知道该脚本上的错误在哪里我的第一个错误是appenChild
我认为我使用var head=document.getElementsByTagName.
更正了...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript</title>
<script type="text/javascript">
function addHTML() {
document.getElementById('testHTML').innerHTML = document.getElementById('txtHTML').value;
document.getElementById('txtHTML').value=''}
function resetHTML() {
document.getElementById('testHTML').innerHTML = '';}
function addJS () {
var newScript= document.createElement('script');
newScript.type='text/javascript';enter code here
newScript.text= document.getElementById('txtjs').value;
var head document.getElementsByTagName('head')[0].appenChild(newScript);
答案 0 :(得分:0)
library(plotly) # version ‘4.7.1’
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv')
df$q <- with(df, cut(pop, quantile(pop)))
levels(df$q) <- paste(c("1st", "2nd", "3rd", "4th", "5th"), "Quantile")
df$q <- as.ordered(df$q)
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showland = TRUE,
landcolor = toRGB("gray85"),
subunitwidth = 1,
countrywidth = 1,
subunitcolor = toRGB("white"),
countrycolor = toRGB("white")
)
p <- plot_geo(df, locationmode = 'USA-states', sizes = c(1, 250)) %>%
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g) %>%
add_markers(x = ~lon, y = ~lat, size = ~pop, color = ~q, text = ~paste(df$name, "<br />", df$pop/1e6, " million")
)
p
据推测,Uncaught TypeError: Cannot read property 'value' of null at addJS
正在返回document.getElementById('txtjs')
。因此,您的HTML可能不包含null
的元素。或许你错了它。或者你可能有一个脚本来动态生成它,但是这个脚本直到这个脚本之后才会运行,我不知道。