Das folgende Beispiel funktioniert auf diese Weise, wenn eine Zeichenfolge zum Textfeld hinzugefügt und dann auf die Schaltfläche geklickt wird, wird ein neues Element zur Liste hinzugefügt. Wenn auf ein Element in der Liste geklickt wird, sollte es durchgestrichen werden.
Code: Select all
$(document).ready(function () {
$('#taskText').keydown(function (evt) {
if (evt.keyCode == 13) {
addTask(this, evt);
}
});
$('#addTask').click(function (evt) {
addTask(document.getElementById('taskText'), evt);
});
// following statements not working
$('#tasks li').live('click', function(evt) {
$(this).addClass('done');
});});
function addTask(textBox, evt) {
evt.preventDefault();
var taskText = textBox.value;
$('').text(taskText).appendTo('#tasks');
textBox.value = "";
};
.done{
text-decoration:line-through;
}
[list]
[/list]
Mobile version