[英]js does not work on mobile but on my computer
我正在構建一個 AJAX 搜索系統,並且在我的計算機上一切正常,但后來我在手機上嘗試了它,但它不起作用。 然后我嘗試了 console.log 並記錄了這些工作,但其他事情沒有。
const btn = document.createElement('button')
btn.innerText = 'hallo'
btn.id = 'test'
document.getElementById('content').append(btn)
const btnEl = document.getElementById('test')
btnEl.addEventListener('click', ()=>
{
alert('hallo')
})
我用 JS 構建了這個簡單的按鈕來測試它是否可以工作,在我的電腦上它工作得非常好,但是在移動設備上這個按鈕甚至沒有顯示
這是AJAX代碼的一部分
suche = ()=>
{
let xhr = new XMLHttpRequest()
this.daten = [];
let produkteEntfernen = ()=>
{
//removes already displayed products
}
let displayProdukte = ()=>
{
//formats the data to html and displays it
}
xhr.onreadystatechange = ()=>
{
if (xhr.status === 200 && xhr.readyState === 4)
{
this.daten = JSON.parse(xhr.response)
produkteEntfernen()
displayProdukte()
}
}
buildRequestUrl = ()=>
{
//returns the url to send to
}
xhr.open('GET', buildRequestUrl())
xhr.send()
}
// the name id is from an input field of type text
let shopSuche = document.getElementById('name')
shopSuche.addEventListener('keyup', ()=>
{
suche()
})
有人知道解決方案或知道我做錯了什么嗎?
append
方法相當新(盡管它的瀏覽器兼容性非常好,即使在移動設備上也是如此)。
對於較舊的瀏覽器,您可能需要改用appendChild
。 在上面的代碼中,您實際上只需要更改方法名稱即可。 ( append
比appendChild
允許更多種類的參數,但是appendChild
支持你所擁有的。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.