I am trying to make a search history log using Local Storage in HTML and I am currently trying to understand how to use the local storage function. Now I have run into an odd problem.
This example works great: http://jsfiddle.net/hr3xQ/17/
But when I try to put it together on my server nothing happens when I try to run the code
<!doctype html>
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8>
<link rel="stylesheet" type="text/css" href="test.css">
<script type='text/javascript'>
$(function () {
$("#submit").click(function () {
var name = $("#name").val();
localStorage.setItem('username',name);
alert(localStorage.getItem('username'));
});
});
</script>
</head>
<body>
name:
<input type="text" id="name">
<br/>
<br/>
<input type="button" id="submit" value="store in local">
</body>
</html>
What am I doing wrong? I'm not very used to web-programming.
You'll need to include jQuery if you want to use jQuery.
In JSFiddle, you get a nice little toggle that allows you to select the frameworks/libraries you'd like to include.
However, when you move your code, the jQuery inclusion doesn't come along with you. You need to either download it or include it via a script
tag in the head
(do it above your other script
so that jQuery loads before you try to use it:
<script src="//code.jquery.com/jquery-latest.min.js"></script>
This is a very common problem: whenever nothing happens
, it's a good idea to check your browser's console. For not including jQuery, you'll often get something like this:
ReferenceError: $ is not defined
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments