我尝试jquery教程,但它没有给出预期的输出

FuC*_*Sam 0 html javascript jquery

当用户单击显示的文本时,此程序将弹出警告消息,然后将文本设置为大写.

<script src="jquery-min.js"></script>
<script>
   //run once the page is loaded
   jquery(document).ready(function ($) {
       //Attach a click event to the span element
       $('#test_span').click(function () {
          //Read the elemnt's current value
          var elemnt_text = $('#test_span').html();
          //display the curretn value of this span
          alert(element_text);
          //convert the value to upper case
          element_text = element_text.toUpperCase();
          //change the span to this new value
          $('#test_span').html(element_text);
       });
  });
</script>
</head>
<span id='test_span'>Testing jQuery</span>
Run Code Online (Sandbox Code Playgroud)

Kri*_*h R 5

试试这个, elemnt_text拼写不正确.使用element_text

要获取元素的文本内容,请使用.text()而不是.html()

var element_text = $('#test_span').text();
Run Code Online (Sandbox Code Playgroud)

代替

 var elemnt_text = $('#test_span').html();
Run Code Online (Sandbox Code Playgroud)

演示: http ://jsfiddle.net/rk72eu8m/

jQuery text()和html()函数之间的区别