Некоторые ошибки о onclick
событие
Следующее является частью моего кода:
var srcElement = null;
var valueElement = null;
showTree = function (item, valueId) {
srcElement = window.event.srcElement;
valueElement = document.getElementById(valueId);
var x = getLeft(item);
var y = getTop(item) + item.offsetHeight;
var w = item.offsetWidth;
blockDTree(x, y, w);
}
getTop = function (e) {
var offset = e.offsetTop;
if (e.offsetParent != null) offset += getTop(e.offsetParent);
return offset;
}
getLeft = function (e) {
var offset = e.offsetLeft;
if (e.offsetParent != null) offset += getLeft(e.offsetParent);
return offset;
}
blockDTree = function (x, y, w) {
var item = $("#combdtree");
item.style.display = 'block';
item.style.top = y;
item.style.left = x;
}
<input type="text" name="" class="FormStyle2" onClick='showTree(this,"pid")' readonly="readonly" placeholder="父节点"/>
<div id="combdtree" class="dtreecob" ></div>
<div class="dtree" style="overflow: auto; width: 100%;">
</div>
однако, когда я запускаю его, я встречаюсь с:
Home:725 Uncaught TypeError: Cannot set property 'display' of undefined
at blockDTree (Home:725)
at showTree (Home:709)
at HTMLInputElement.onclick (Home:63)
Что не так с кодом? Меня смущало два дня. Как решить это?