首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将属性表显示为x3dom对象的弹出窗口

将属性表显示为x3dom对象的弹出窗口
EN

Stack Overflow用户
提问于 2012-12-18 06:51:42
回答 2查看 825关注 0票数 2

我是这个领域的新手,一直在尝试使用x3dom对象。我现在面临的问题是如何将x3dom对象的属性显示为弹出窗口。我已经看过x3dom网站上给出的例子,但还没有找到相关的例子。如果有人有一些例子可以分享,我会很高兴的。提前谢谢你。

EN

回答 2

Stack Overflow用户

发布于 2012-12-19 00:14:10

您可以使用attributes属性(例如,document.getElementById("id").attributes),下面是一个示例,当您单击任一按钮时,它将显示一个属性表:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
    <title>X3DOM</title>
    <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.0.4/css/bootstrap.min.css" rel="stylesheet" />

</head>
<body class="container">


    <X3D width="100%" height="300px">
        <Scene>
            <Shape id="myShape">
                <Appearance>
                    <Material id="myMaterial" diffuseColor="0.6 0.6 0.6" specularColor="0.8 0.8 0.8" shininess="0.145" ambientIntensity="0.2" emissiveColor="0,0,0"/>
                </Appearance>
                <Sphere />
            </Shape>
        </Scene>
    </X3D>


    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://x3dom.org/x3dom/release/x3dom.js"></script>
    <script>
    function displayAttributes(objectId){
        var code = '';
        var attributes = document.getElementById(objectId).attributes;
        $.each(attributes, function(index, attr) {
            code += '<tr><th>' + attr.name +'</th><td>' + attr.value + '</td></tr>';
        });
        $("#attributesTable").html(code);
    }
    </script>


    <button onclick="displayAttributes('myShape')" class="btn btn-large">Attributes of the shape</button>
    <button onclick="displayAttributes('myMaterial')" class="btn btn-large">Attributes of the material</button>

    <table id="attributesTable" class="table table-striped table-bordered" style="margin-top:50px"></table>


</body>
</html>

要点:https://gist.github.com/4329304

票数 0
EN

Stack Overflow用户

发布于 2012-12-23 17:53:06

你到底在尝试什么是不清楚的,不确定这是否有帮助

代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="http://x3dom.org/x3dom/example/x3dom.css"></link>
<script type="text/javascript" src = "http://x3dom.org/x3dom/example/x3dom.js"></script>
</head>
<body>
<X3D showLog='true' width="400px" height="400px"><Scene>
<Shape><Box size="2 2 2" onclick="alert_attributes();" /></Shape>
</Scene></X3D>
<script>
function alert_attributes()
{
var size = document.getElementsByTagName("Box")[0].getAttribute('size');
x3dom.debug.logInfo( size );
alert( size );

}
</script>
</body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13923592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档