중요한주의 사항 사람들이 잡히지 않아 (내가 한 것처럼) : 이것은 jQuery처럼 보일 수 있습니다. 이지만이 아닙니다.
솔직히 말해서 나는 더 잘 알려야했습니다. 나는 jQuery 이외의 것을 $
으로 사용한다. 오 잘. 수업은 배웠다!함수를 실행할 수 없습니다.
(HTML) :
<html>
<head>
<script src="selector.js"></script>
</head>
<body>
<label id="id">A label</label>
<script>
$("label #id").clicked(function(){
alert("ASDASD");
});
</script>
</body>
</html>
(JS) : 내가 레이블을 클릭하면
/*
NAME : SELECTOR.JS
*/
function $(attr){
// Removed space in front of the variable
while(attr.charAt(0) == " "){
attr = attr.substr(1);
if(attr == ""){
return 0;
}
}
// Completed the query
if(attr.length > 1){
return Array.prototype.slice.call(document.querySelectorAll(attr));
}else{
if(attr.length == 1){
return new Object(document.querySelector(attr));
}else{
return null;
}
}
}
Object.prototype.clicked = function(script){
if(typeof(this) == "object"){
if(this.constructor == Array){
for(var i = 0; i < this.length; i++){
this[i].onclick = script;
}
}else{
if(this.constructor == Object){
console.log("SINGLE OBJECT : " + this);
console.log("SINGLE OBJECT : ONCLICK : " + this);
this.onclick = script;
}else{
console.log("ERROR : this.constructor is not 'Object' or 'Array'.");
return null;
}
}
}else{
console.log("ERROR : typeof(this) is not 'Object'.");
return null;
}
return this;
};
, 내가 얻을 수없는 경고 상자 다크 Absol
코드 ~ NIET 본. 어떻게해야합니까? js 파일의 파일 이름은 selector.js입니다. 나는 달릴 기능이 필요합니다. Pls 도움!
나는 이것이 최소화 된 코드라고 생각합니다.
을'id'은 * 그는'
gshhh .... downvoters 오늘 바쁘다 :-) –
Downvoters 내 정확한 대답에 투표했다. Argh –