jQuery 设置 li 的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17190207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting text of li
提问by maximus
I have made list:
我已经列出了:
<ul>
<li id="one"></li>
</ul>
And then in jQuery I do:
然后在 jQuery 我做:
$("#one").text("one");
However it is not changing, also I have tried using .val()
but it didn't help.
然而它并没有改变,我也试过使用.val()
但它没有帮助。
Why it happens and how to change the li text?
为什么会发生这种情况以及如何更改 li 文本?
回答by PSR
There may be one of the problem you have
可能存在您遇到的问题之一
1) You did not imported js files properly
1)你没有正确导入js文件
2)You might not write the code in ready function
2)您可能不会在就绪函数中编写代码
Write your code in ready function and import jQuery related js files.
在就绪函数中编写代码并导入与 jQuery 相关的 js 文件。
$( document ).ready(function() {
$("#one").text("one");
});