简单更改localStorage名称提示符不显示

时间:2016-06-24 15:04:29

标签: javascript

我在这里学习基本的localStorage:

https://developer.mozilla.org/en-US/Learn/Getting_started_with_the_web/JavaScript_basics#Adding_a_personalized_welcome_message

问题:每次单击“更改用户”按钮

时,我都应该能够更改存储的名称

https://jsfiddle.net/19bvwypn/

var myButton = document.querySelector('button');    
var myHeading = document.querySelector('h1');

function setUserName() {
  var myName = prompt('Please enter your name.');
  localStorage.setItem('name', myName);
  myHeading.innerHTML = 'Mozilla is cool, ' + myName;
}

if(!localStorage.getItem('name')) {
  setUserName();
} else {
  var storedName = localStorage.getItem('name');
  myHeading.innerHTML = 'Mozilla is cool, ' + storedName;
}

myButton.onclick = function() {
  setUserName();
}

但没有任何反应。 它在Mozilla自己的示例站点上工作正常: https://mdn.github.io/beginner-html-site-scripted/

有人能告诉我我在这里俯瞰的是什么吗? : - )

1 个答案:

答案 0 :(得分:1)

@Capax您的代码100%有效,但您忘记在HTML添加<h1></h1>,只需在button之后添加import numpy as np npA = np.array(a) npB = np.array(b) npA[:, None] + npB array([[ 1.31, 1.51, 2.71, 2.41, 5.81, 10.01], [ 1.42, 1.62, 2.82, 2.52, 5.92, 10.12], [ 1.33, 1.53, 2.73, 2.43, 5.83, 10.03], [ 7.9 , 8.1 , 9.3 , 9. , 12.4 , 16.6 ], [ 3.7 , 3.9 , 5.1 , 4.8 , 8.2 , 12.4 ], [ 4. , 4.2 , 5.4 , 5.1 , 8.5 , 12.7 ]]) 。然后你的小提琴就没有问题了。 :)

这是 Working Fiddle

<强>感谢