Created
December 19, 2012 07:54
-
-
Save iEverX/4335136 to your computer and use it in GitHub Desktop.
Add tags. Need jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#input_outer { | |
border: 1px solid orange; | |
border-radius: 3px; | |
padding: 2px; display: | |
inline; width: 200px; | |
overflow: hidden; | |
} | |
.t_input { | |
width: 100px; | |
border: none; | |
outline: none; | |
} | |
.tag { | |
background-color: rgba(102, 195, 242, 0.5); | |
padding: 0 5px; | |
margin-right: | |
3px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Tag INPUT</title> | |
<link rel="stylesheet" href="tag.css"> | |
<script type="text/javascript" src="../jquery-1.8.3.js"></script> | |
</head> | |
<body> | |
<div id="input_outer" node-type="container"> | |
<input type="text" class="t_input" id="now_input"> | |
</div> | |
<script type="text/javascript" src="./tag.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function (){ | |
$('#input_outer').focus(focusOnNowInput).click(focusOnNowInput); | |
$('#now_input').keydown(function(event) { | |
var keycode = event.keyCode; | |
if (event.keyCode == 32) { | |
if ($.trim(this.value) != '') { | |
$('<span class="tag"></span>').html($.trim(this.value)).insertBefore(this); | |
this.value = ''; | |
} | |
return false; | |
} | |
else if (event.keyCode == 8) { | |
if ($.trim(this.value) == '') { | |
$('.tag').last().remove(); | |
} | |
} | |
}); | |
}); | |
function focusOnNowInput() { | |
$('#now_input')[0].focus(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment