Javascript 从innerHTML列表中的按钮获取getElementById

Javascript 从innerHTML列表中的按钮获取getElementById,javascript,html,gis,arcgis-js-api,Javascript,Html,Gis,Arcgis Js Api,我需要重置用户输入的变量,该变量位于由esri JavaScript API中的扩展函数调用的innerHTML列表中 这段代码正在构建扩展小部件 // Displays instructions to the user for understanding the sample // And places them in an Expand widget instance const sampleInstructions = document.createElement('div'); sam

我需要重置用户输入的变量,该变量位于由esri JavaScript API中的扩展函数调用的innerHTML列表中

这段代码正在构建扩展小部件

// Displays instructions to the user for understanding the sample
// And places them in an Expand widget instance
const sampleInstructions = document.createElement('div');
sampleInstructions.style.padding = '10px';
sampleInstructions.style.backgroundColor = 'rgba(12, 32, 116, 0.6)';
sampleInstructions.style.color = '#dbdbdb';
sampleInstructions.style.fontFamily = 'Arial, Helvetica, sans-serif';
sampleInstructions.style.width = '450px';
sampleInstructions.innerHTML = [
    '<div class="instruct">',
    'Use the input below to designate the buffer distance (in miles) to aggregate all variables (in right side panel).<br><br>',
    '</div>',
    '<div class="inputDiv">',
    '<label for="userInput" class="userInputLabel">Set Buffer Radius (miles) for Aggregation</label>',
    '<input type="number" id="input-number" class="radiusInput" placeholder="Radius" min="0" step="0.5"></input>',
    '<button type="button" id= clear> Click here to clear </button>',

    '</div>'
].join(' ');
此代码将小部件添加到web应用程序

const instructionsExpand = new Expand({
    expandIconClass: 'esri-icon-description',
    expandTooltip: 'Set Aggregate Buffer',
    view: view,
    content: sampleInstructions,
    expanded: view.widthBreakpoint !== 'xsmall'
});

问题可能是扩展小部件正在动态加载页面加载中DOM中未加载的html元素。因此,必须将click事件绑定到整个文档,而不是特定的clear按钮

document.addEventListener("click", event => {
    if(event.target.id == 'clear') clearGeometry();
});

// Clear the geometry and set the default renderer
function clearGeometry() {
    clearCharts();
    document.getElementById('input-number').value = ''
    if (highlightHandle) {
        highlightHandle.remove();
        highlightHandle = null;
    }
}
document.addEventListener("click", event => {
    if(event.target.id == 'clear') clearGeometry();
});

// Clear the geometry and set the default renderer
function clearGeometry() {
    clearCharts();
    document.getElementById('input-number').value = ''
    if (highlightHandle) {
        highlightHandle.remove();
        highlightHandle = null;
    }
}