저는 HTML, JavaScript 및 Jquery를 처음 사용합니다. 내가 왜 Val ("")을 호출 한 후에 Append()가 더 이상 TextArea에 텍스트를 추가하지 않는지 알 수 없습니다. 검색을 시작할 때마다 TextArea의 텍스트를 지우려고하기 때문에 Val ("")을 호출해야하는 이유입니다. 그래서 UI에서 게임이나 회사 이름의 텍스트를 입력 한 다음 버튼을 눌러 입력 필드를 기반으로 게임을 검색합니다. 아래는 site.js의 코드입니다. 감사.Jquery Val()을 호출 한 후 Append()가 작동하지 않습니다.
var arr = [
{
Game:"Double Dragon",
Developer: "Technos Japan Corp",
Publisher: "Acclaim",
Platform: {
Console: "Nintendo"
}
},{
Game:"Street Fighter 2000",
Developer: "Capcom",
Publisher: "Capcom",
Platform: {
Console: "Nintendo"
}
},{
Game:"Super Mario Bros.",
Developer: "Nintendo",
Publisher: "Nintendo",
Platform: {
Console: "Nintendo"
}
},{
Game:"Secret Mana",
Developer: "SquareSoft",
Publisher: "SquareSoft",
Platform: {
Console: "Super Nintendo"
}
},{
Game:"Final Fight",
Developer: "Capcom",
Publisher: "Capcom",
Platform: {
Console: "Super Nintendo"
}
},{
Game:"Super Contra",
Developer: "Konami",
Publisher: "Konami",
Platform: {
Console: "Nintendo"
}
},{
Game:"Mega Man",
Developer: "Capcom",
Publisher: "Capcom",
Platform: {
Console: "Nintendo"
}
}
];
function GameBtnEvent()
{
//$("#textAreaText").val('');//if I comment this out, Append() call will work, otherwise Append() does not append text to TextArea
DisplayResults();
}
function DisplayResults()
{
var found = 0;
$.each(arr, function (index, value) {
var gameName = $("#searchTitle").val();
var companyName = $("#selectionBlock").val();
if(companyName.toLowerCase() == value.Publisher.toLowerCase())
{
$('#textAreaText').append("Title: " + value.Game + "\n");
$('#textAreaText').append("Company: " + value.Publisher + "\n");
$('#textAreaText').append("Console: " + value.Platform.Console + "\n\n");
found = 1;
}
else if(companyName.toLowerCase() == value.Publisher.toLowerCase() &&
gameName.toLowerCase() == value.game.toLowerCase())
{
$('#textAreaText').append("Title: " + value.Game + "\n");
$('#textAreaText').append("Company: " + value.Publisher + "\n");
$('#textAreaText').append("Console: " + value.Platform.Console + "\n\n");
found = 1;
}
});
if(found == 0)
{
$("#textAreaText").append("game not found");
}
}
업데이트 : 그것은이 동작은 크롬에서 발생 보이지만 탐색기 아무 문제가 없습니다.
와우, 저는'.val()'과 같은 setter에 함수 인자를 사용하는 방법을 알고있는 유일한 사람이 아닙니다. – Barmar
귀하의 코드를 사용하는 경우 귀하의 빠른 응답 주셔서 감사합니다,하지만 난 ("안녕하세요") 기능을 DisplayResults() 그냥 코드가 응답하지 않는 이유를 디버깅하기 위해 경고를 팝업 그래서 심지어 팝업하지 않습니다. 그래서 나는 그것을 잘못 복사했다고 생각합니다. – Phil
어딘가에 오류가있는 것 같습니다. 자세한 내용은 콘솔 확인 –