我正在研究 MVC4 jQuery。我需要找到标签下的按钮 ID anchor
。这是我的 jQuery 代码:
// drop event handler
addEvent(dropAreas, 'drop', function (event) {
alert(5);
if (event.preventDefault) event.preventDefault();
// get dropped object
var iObj = event.dataTransfer.getData('obj_id');
var oldObj = document.getElementById(iObj);
// get inner text
var linkText = oldObj.innerHTML;
oldObj.className += 'hidden';
// remove object from DOM
oldObj.parentNode.removeChild(oldObj);
// add similar object in another place
this.innerHTML += '<a id="' + iObj + '" draggable="true">' + linkText + '<button id="btnAdd " style="height:20px;width:20px;">Add</button></a>';
// and update event handlers
updateHandlerDrag();
this.style.borderColor = "#ccc";
return false;
});
在这一行中,我在上面的代码中定义了一个按钮:
this.innerHTML += '<a id="' + iObj + '" draggable="true">' + linkText + '<button id="btnAdd " style="height:20px;width:20px;">Add</button></a>';
在上面的代码中,我在锚标记中给出了一个按钮,我需要在下面的代码中触发该 id:
// add SubMenu
var addColBtn = document.querySelectorAll('#btnAdd ');
addEvent(addColBtn, 'click', function (event) {
alert('addingSubmenu');
if (event.preventDefault) event.preventDefault();
alert('adding');
// recalculate widths for columns
var oCols = document.querySelector('div.columns');
alert(sub);
var iChilds = oCols.childElementCount + 1;
var dWidth = 50 / iChilds;
// add single column
oCols.innerHTML += '<div class="columns" id="drop_' + (iChilds + 1) + '" droppable="true"><img src="images/delete.png" onclick="removeColumn(this)" /></div>';
// set new widths
for (var i = 0; i < iChilds; i++) {
oCols.children[i].style.width = dWidth + '%';
}
// update handlers
updateHandlerDrop();
return false;
});
我怎样才能做到这一点?