Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery-get.html()在使用.html()设置之后_Javascript_Jquery_Local Storage - Fatal编程技术网

Javascript JQuery-get.html()在使用.html()设置之后

Javascript JQuery-get.html()在使用.html()设置之后,javascript,jquery,local-storage,Javascript,Jquery,Local Storage,我使用的jQuery具有本地存储的强大功能 以下是我所拥有的: <textarea name="localStorageString" id="localStorageString"></textarea> <script> var userJson = localStorage.getItem('userJson'); $('#localStorageString').html(userJson); $('#localStorageString'

我使用的jQuery具有本地存储的强大功能

以下是我所拥有的:

<textarea name="localStorageString" id="localStorageString"></textarea>
<script>
  var userJson = localStorage.getItem('userJson');
  $('#localStorageString').html(userJson);
  $('#localStorageString').keyup(function(){
    alert($(this).html());
});

var userJson=localStorage.getItem('userJson');
$('#localStorageString').html(userJson);
$('#localStorageString').keyup(函数(){
警报($(this.html());
});
textarea
已正确填充,问题是当我修改它时,它总是警告相同的值(由
html(userJson)
设置)


有什么想法吗?

不要使用
html()
,使用
val()
你需要
$(this).val()
来获取表单元素的值。

简单:不要在
(或其他表单元素)上使用
.html()
。使用(或
.value

尝试使用
.val()
而不是
.html()

.val()

.html()

我忘了这个。为什么
.html()
不起作用

html()
-这是本机JavaScript
.innerHTML
函数。它将标记内的所有内容(所有节点)作为字符串

<div id="Node">
   <a href="#">Hello</a>
</div>
console.info($('#Node').html()); // <a href="#">Hello</a>

console.info($('#Node').html());//

val()。但是对于textarea,为什么结果不一样呢?它的jQueryAPI。我猜它提供了对表单元素及其值的统一访问。这真的很有道理。
$('#localStorageString').val(userJson)
.keyup(function() {
    console.log(this.value);
});