【问题标题】:Return undefined error when getting button value获取按钮值时返回未定义的错误
【发布时间】:2020-06-20 15:22:58
【问题描述】:

我有以下代码。我面临在警报中收到未定义的问题。有人知道为什么吗?

<div><button class='hello' value='hello1'>Show</button></div>

viewer.infoBox.frame.addEventListener('load', function() {
       
        // Now that the description is loaded, register a click listener inside
        // the document of the iframe.
       
        viewer.infoBox.frame.contentDocument.body.addEventListener('click', function(e) {
           
            // The document body will be rewritten when the selectedEntity changes,
            // but this body listener will survive.  Now it must determine if it was
            // one of the clickable buttons.
            
             alert(e.target.value);
         
        }, false);
    }, false);

更新:我设法让它在这个sandbox 上工作,但无法在本地主机上这样做。有什么想法吗?

【问题讨论】:

  • 什么是 viewer.infoBox.frame - 请点击编辑和[&lt;&gt;] sn-p 编辑器并提供minimal reproducible example
  • @mplungjan 我已经更新了一个例子。
  • 不知道。对不起。

标签: javascript iframe target cesium


【解决方案1】:

点击事件监听器可能没有 e.target.value。也许您只是在寻找 e.target。您可以 console.log(e) 并查看它为您提供的每个值。

【讨论】:

  • 那么它可能与 viewer.infoBox.frame.contentDocument.body 有关。那是什么?根据我的研究,这是一张地图。我见过人们使用事件“点击”而不是“点击”。可以试试。
猜你喜欢
  • 1970-01-01
  • 2013-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多