JavaScript Document.ActiveElement在移动设备上未定义

发布于 2025-01-31 12:35:12 字数 615 浏览 4 评论 0原文

因此,当前此功能可用于台式机,但是当我在移动设备上进行测试时,我会获得“未定义”。我检查了一下iPhone Safari上的Activelement是否兼容,并说它在那里工作,所以我目前迷路了。有任何修复或替代方案吗?

这是选择的按钮。

<input type='button' id='slogan-button' onclick='changeSlogan()' value='Junior Varsity'>

这是使其正常工作的功能。

<script>
    function changeSlogan() {
        const activeSlogan = document.activeElement.value;
      document.getElementById('slogan-input').value = activeSlogan;
      document.getElementById('slogan-display').innerHTML = activeSlogan;
    }
</script>

这应该允许选择一个口号,并将口号的值添加到输入中,我仅在桌面上获得所选口号的相等值。

So currently this function works on desktop but when I test it on mobile I get "undefined." I checked to see if activeElement is compatible on iPhone safari and it says it works there so I'm currently lost. Any fixes or alternatives?

This is the button that is selected.

<input type='button' id='slogan-button' onclick='changeSlogan()' value='Junior Varsity'>

This is the function to make it work.

<script>
    function changeSlogan() {
        const activeSlogan = document.activeElement.value;
      document.getElementById('slogan-input').value = activeSlogan;
      document.getElementById('slogan-display').innerHTML = activeSlogan;
    }
</script>

This is supposed to allow a slogan to be selected and the value of the slogan is added into a input, I get the equal value of the selected slogan only on desktop.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安人多梦 2025-02-07 12:35:12

ActiveEllement的定义是当前焦点的元素。可集中的要素因平台而没有保证。例如,MacOS仅认为输入是可集中的。根据您所写的内容,iOS似乎是相同的。

改用“点击”事件。

The definition of an ActiveElement is an element which is currently in focus. The elements which are focusable vary by platform with no guarantees. For example, MacOS only considers inputs to be focusable. Based on what you wrote, it seems like iOS is the same.

Use the “click” event instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文