$(document).ready(function() {
$('input.clear').click(function() {
$('input.input').val('');
$('p.display').text('The value of the text input is: ');
});
$('input.input').on('keyup change', function() {
$('p.display').text('The value of the text input is: ' + $(this).val());
});
})
DEMO 1
也許這個解決方案可以幫助你:
$(document).ready(function() {
$('input.clear, input[type=reset]').on('click', function() {
$('input.input').val('').change();
$('p.display').text('The value of the text input is: ');
});
$('input.input').on('keyup change', function() {
$('p.display').text('The value of the text input is: ' + $(this).val());
});
});
DEMO 2
叫我只是對這個同樣的問題,今天的工作。 jQuery'.on'事件應該可以解決這個問題,但是我無法讓它工作。 $(「#ElementID」)。on(「input change property change paste keyup」,handler)'...... –
嗯......我以前從來沒有用過'.on()'。我會研究它 –
我以前使用過'.live()',但從1.7版本開始已被棄用,'.on()'現在是首選方法 –