點晴ERP-動態在新增送貨單上添加搜索銷售單號功能
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
![]() // 獲取 id 為 'searchInput' 的元素 var searchInputElement = document.getElementById('contract_id'); searchInputElement.style.width="48%" // 獲取該元素所在的 td var parentTd = searchInputElement.closest('td'); var inputElement = document.createElement("input"); inputElement.type = "text"; inputElement.style.width="48%" inputElement.style.marginLeft = "0px"; inputElement.id = "searchInput"; inputElement.placeholder = "請輸入模板關鍵詞..."; inputElement.autocomplete = "off"; // 創建新的 div 元素 var divElement = document.createElement("div"); divElement.id = "dropdown"; divElement.style.width = "100px"; divElement.style.marginLeft = "0px"; divElement.style.index= "2"; // 將 input 元素和 div 元素添加到 td 中 parentTd .appendChild(inputElement); parentTd .appendChild(divElement); document.getElementById('searchInput').addEventListener('input', function() { const query = this.value.toLowerCase(); const dropdown = document.getElementById('dropdown'); const originalselect = document.getElementById('contract_id'); dropdown.innerHTML = ''; if (query) { dropdown.style.display = 'block'; Array.from(originalselect.options).forEach(option => { if (option.text.toLowerCase().includes(query)) { const div = document.createElement('div'); div.textContent = option.text; div.className = 'dropdown-item'; div.onclick = function() { document.getElementById('searchInput').value = option.text; option.selected=true; originalselect.onchange(); dropdown.style.display = 'none'; }; dropdown.appendChild(div); } }); } else { dropdown.style.display = 'none'; } }); document.addEventListener('click', function(event) { const dropdown = document.getElementById('dropdown'); if (!document.getElementById('searchInput').contains(event.target)) { dropdown.style.display = 'none'; } }); 該文章在 2025/3/17 14:43:23 編輯過 |
關鍵字查詢
相關文章
正在查詢... |