For some reason my code below is not working even it is identical with someone's code that is actually running ok in chrome. I am using chrom and jquery 1.10.1 the keycode just doesn't fire.
<ul id="tasks"></ul>
<input type="text" id="taskText" >
$(function() {
$('#taskText').keydown(function(evt) {
if (evt.keyCode == 13) {
var taskText = this.value;
$('<li>').text(taskText).appendTo('#tasks');
$(this).val() = "";
}
});
});
You have a typo: $(this).val() = "";
Firebug shows that Chrome is throwing a parse error, so the script will not run at all. You need of course:
$(this).val("");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.