jquery 和动态表单有帮助吗?

发布于 2024-12-02 02:26:55 字数 722 浏览 0 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北凤男飞 2024-12-09 02:26:55

使用 $(document).ready(); http://api.jquery.com /准备好/
喜欢

$(document).ready(function(){
    var value = "hello";
    $('#login [name=firstname]').val(value)
});

在文档完全加载并且正确创建 DOM 后设置初始值

use $(document).ready(); http://api.jquery.com/ready/
like

$(document).ready(function(){
    var value = "hello";
    $('#login [name=firstname]').val(value)
});

to set initial values after document fully loads and DOM is created properly

烂柯人 2024-12-09 02:26:55

插入 jquery 的方式和时间存在问题,请尝试以下操作:

<!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>
</head>
<body>
<form id="login">
    <input type = "text" name="firstname">
</form>



<script type = "text/javascript" src="{{ STATIC_URL }}js/jquery.js"></script>
<script type = "text/javascript">
    var value = "hello";
    $('#login [name=firstname]').val(value)
</script>
</body>
</html>

there is a problem with how and when you insert jquery try the following:

<!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>
</head>
<body>
<form id="login">
    <input type = "text" name="firstname">
</form>



<script type = "text/javascript" src="{{ STATIC_URL }}js/jquery.js"></script>
<script type = "text/javascript">
    var value = "hello";
    $('#login [name=firstname]').val(value)
</script>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文