jquery 和动态表单有帮助吗?
我对 jquery 很陌生,我正在尝试按以下方式制作动态表单(但它不起作用)。我希望表单的初始值为“hello”,如标题区域中所述。
我知道您可以使用 html (使用 value 参数)轻松完成此操作,但我心中有一个更大的目标,要求该值是动态的。
无论如何,我似乎无法让它工作,所以请帮忙。谢谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Logging In Test</title>
<script type = "text/javascript" src="{{ STATIC_URL }}js/jquery.js">
var value = "hello";
$('#login [name=firstname]').val(value)
</script>
</head>
<body>
<form id="login">
<input type = "text" name="firstname">
</form>
</body>
</html>
谢谢。!
I'm very new to jquery, and I'm trying to make a dynamic form in the following manner (and its not working). I want the form to have an initial value of "hello" as stated in the header region.
I understand that you can do this easily with html (with the value parameter), but I have a much larger goal in mind that requires the value to be dynamic.
Anyway, I just can't seem to get it to work, so help please. Thank you.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Logging In Test</title>
<script type = "text/javascript" src="{{ STATIC_URL }}js/jquery.js">
var value = "hello";
$('#login [name=firstname]').val(value)
</script>
</head>
<body>
<form id="login">
<input type = "text" name="firstname">
</form>
</body>
</html>
Thank you.!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
$(document).ready();
http://api.jquery.com /准备好/喜欢
在文档完全加载并且正确创建 DOM 后设置初始值
use
$(document).ready();
http://api.jquery.com/ready/like
to set initial values after document fully loads and DOM is created properly
插入 jquery 的方式和时间存在问题,请尝试以下操作:
there is a problem with how and when you insert jquery try the following: