0
나는 다음 코드를 가지고 있는데, 나는 JavaScript에 비해 상대적으로 새로운 편이다. 그래서 아무도 내가 1 단계로 나아 가지 않고 왜 그것이 완료되었는지 보여주지 못한다고 말할 수 있을까?jQuery의 발전 단계
$(function(){
var textContainer = $('#text'),
inputLine = $('input');
textContainer.text('What is your name?');
inputLine.focus().on('keyup', function(e){
if (e.which === 13) {
e.preventDefault();
textContainer.text('Hi there, ' + this.value + '.');
this.value = "";
}
});
});
이 방법 stage
없다 : 당신은 많은 의미가하지 않는, 그래서이 추측하고있어 무엇
var textContainer = '#text';
var inputLine = 'input';
var username = null;
var stage = 0;
$(function(){
if(0 == stage){
$(function(){
$(textContainer).text('What is your name?');
$(inputLine).focus();
$(inputLine).keypress(function(e){
if (e.keyCode == 13 && !e.shiftKey) {
e.preventDefault();
username = $(this).val();
$(this).val('');
stage = 1;
}
});
});
}
if(1 == stage){
$(textContainer).text('Hi there, ' + username + '.');
}
});
이 함수를 호출하는 코드는 어디에 있습니까? –
'$ (function() {'은'$ (document) .ready()'의 줄임말입니다.) – Blender
다음 if 문으로 넘어 가고 싶었습니다 (if (1 == stage)) – JazzyP