最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change textbox value using jQuery - Stack Overflow

programmeradmin1浏览0评论

I usually don't program in jQuery so I'm a big newbie. I got an HTML input form (type=text) and I want that when website is loaded, the value of the textbox should change.

I got this in fill-in.php file:

<script src="fill.js"></script>
<body>
<label class="txtlabel">Username/Email</label>
<input id="username" value="Moin" type="text" name="login-username">
<label class="txtlabel">Kennwort</label>
<input id="kennwort" value="Passwort" type="password" name="login-password">
</body>

And in fill.js file I wrote this:

$(document).ready(function(e) {
    $('#username').val('some random text')
});

fill.js is correctly linked to my fill-in.php file.

Can someone give me a hint where I made a mistake?

Cheers

I usually don't program in jQuery so I'm a big newbie. I got an HTML input form (type=text) and I want that when website is loaded, the value of the textbox should change.

I got this in fill-in.php file:

<script src="fill.js"></script>
<body>
<label class="txtlabel">Username/Email</label>
<input id="username" value="Moin" type="text" name="login-username">
<label class="txtlabel">Kennwort</label>
<input id="kennwort" value="Passwort" type="password" name="login-password">
</body>

And in fill.js file I wrote this:

$(document).ready(function(e) {
    $('#username').val('some random text')
});

fill.js is correctly linked to my fill-in.php file.

Can someone give me a hint where I made a mistake?

Cheers

Share Improve this question asked Oct 2, 2013 at 12:21 roemelroemel 3,2974 gold badges31 silver badges56 bronze badges 14
  • 1 whether jQuery library is included.... check your browser console to see whether there are any errors – Arun P Johny Commented Oct 2, 2013 at 12:22
  • 1 f12 is your friend, what is the error in the console if there is one? – epascarello Commented Oct 2, 2013 at 12:22
  • 3 Close these input tags! – emerson.marini Commented Oct 2, 2013 at 12:23
  • 1 @AdamWolski the right question is: Why not? It doesn't cause any harm to keep the markup well formed. – emerson.marini Commented Oct 2, 2013 at 12:25
  • 2 You didn't add the jQuery library. – emerson.marini Commented Oct 2, 2013 at 12:26
 |  Show 9 more ments

3 Answers 3

Reset to default 2

Add this in your header section

<script src="https://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>

If you're planning to use jQuery, the very first thing you need is the library. You can reference it from a CDN or download it:

http://jquery./download/

<!-- CDN reference (Google) -->
<script src="//ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="fill.js"></script>

you need to include the jquery library before the fill.js, you can download it from the jQuery site or use a CDN version as given below

<script src="http://code.jquery./jquery-1.10.2.min.js"></script>
<script src="fill.js"></script>
发布评论

评论列表(0)

  1. 暂无评论