안녕하십니까. ^^
입력 만들기에 함수를 사용하고 싶지만 객체 (예 : 사용자 정의 입력 만들기)와 같이 변수 뒤에 변수 이름 (예 : "이름")을 지정하고 싶습니다. 그 후 (작성 및 확인) 첫 번째 HTML 코드에서 div "userInfo"에 입력을 삽입하고 두 번째 입력에서 값을 확인하려는 기능을 사용하고 싶습니다.전역 변수에서 객체 함수를 사용할 수없는 이유는 무엇입니까?
문제는 개체를 전역 변수 "name"에 연결 한 후 해당 함수를 사용하면 브라우저의 콘솔에서 name.create()가 함수가 아니므로 사용할 수 없습니다.
불쌍한 영어와
감사합니다 모두에 자바 스크립트의 xD 내 멍청한 놈 수준
function createAll() {
name = new textInput("nameInput", 8, 24, "a-Z0-9", "required");
concatFirst += name.create();
document.getElementById("userInfo").innerHTML = concatFirst;
console.log(JSON.stringify(name));
}
function textInput(idInput, minlenght, maxlenght, req, requiredOption) {
this.idIn = idInput;
this.minLong = minlenght;
this.maxLong = maxlenght;
this.reqCha = req;
this.requiredOpt = requiredOption;
this.create = function() {
return "<p> \
<input id='" + this.idIn + "' pattern='[" + this.reqCha + "]{" + this.minLong + ",}' maxlenght='" + this.maxLong + "' " + " onchange='name.check()' onmouseover='name.check()' " + this.requiredOpt + " ></input> \
</p>";
}
this.check = function() {
document.getElementById(this.idIn).style.boxShadow = "0 0 10px 3px green";
}
}
<html>
<body onload="createAll();">
<div id="mainForm">
<!-- First Form -->
<div id="userInfo">
</div>
</div>
</body>
</html>
* "... 예 : 'name'"* - 다른 변수를 사용해 보셨습니까? 이름 'name'이 문제의 원인 일 수 있습니다. – GolezTrol