javascript - 如何在 Cognos11 中使用 getElementBy 获取文本元素的值?
问题描述
Heiho:-)## 我在Cognos 11 报告中获得了一些文本元素/单例,以显示一些计算值。我用d3.js添加了一些JavaScript来可视化这些值。
我尝试使用document.getElementsByClassName()从文本元素中获取值。它可以在 HTML 编辑器中使用,但是当我在Cognos中的JavaScript中尝试它时却不行。我只是在我的警报消息中得到“未定义” 。我在Cognos中的文本元素有一个名为"fname"的类。当我在脚本中使用硬编码值时,脚本的其余部分可以工作并显示图表。
HTML 编辑器
<!DOCTYPE html>
<html>
<body>
<input class="fname" type="text" value="Michael">
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementsByClassName("fname")[0].value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
用于 Cognos 的 JavaScript
define(["http://d3js.org/d3.v4.min.js"], function (d3) {
"use strict";
function D3Chart()
{
};
D3Chart.prototype.draw = function( oControlHost )
{
var fname = document.getElementsByClassName("fname")[0].value;
window.alert(fname);
//some code
};
D3Chart.prototype.setData = function( oControlHost, oDataStore)
{
};
return D3Chart;
});
解决方案
推荐阅读
- django - 将自定义 UserCreationForm 与 GeoDjango 管理员 (OSMGeoAdmin) 一起使用
- python - 处理 apache 梁中的列?主要是前向填充
- javascript - JavaScript - 获取具有特定值的对象的计数
- c# - 注入基本控制器而不从继承一个传递的正确方法
- php - PHP从嵌套JSON数组中的第N个数组中获取键和值
- python - 当“鼠标在按钮上”时,我应该如何获得信号?(刚开,未按下)
- c++ - Boost asio 库最新版本中缺失方法的替代方法
- google-cloud-platform - 从 Cloud Run 连接到 Memorystore
- angular - 为什么我会收到“src/app/component.service.ts(9,29) 中的错误:错误 TS2304:找不到名称 'Http'。” 在角度?
- sql - 在 SQL 中执行语句后所有数据为 NULL