我的框架有这个选择器代码,但我遇到了一些问题。
function $elect(id) {
if (!(this instanceof $elect)) {
return new $elect(id);
}
this.elm = document.getElementById(id);
}
我已经为此分配了一些方法,到目前为止它工作正常。我也想在没有方法的情况下使用它。喜欢var input = $elect('inputbox');
,但这不起作用。
var input1 = $elect('inputbox');
var input2 = document.getElementById('inputbox');
他们不会返回相同的东西。第一个返回[object Object]
错误,第二个返回[object HTMLTextAreaElement]
。它应该像第二个一样返回。我怎样才能做到这一点?