JS Universal apps "无法获取property 'style'未定义或空引用的

JS Universal apps "Unable to get property 'style' of undefined or null reference"

本文关键字:未定义 style 引用 获取 apps Universal quot JS property      更新时间:2023-09-26

我正在尝试使用Javascript项目在MS Universal应用程序中设置旋转

但是我收到以下错误信息

>0x800a138f - JavaScript运行时错误:无法获取未定义或空引用的属性"style"


我已经在整个web中查看了几个错误报告,我看到的大部分是元素首先必须创建,但在我的情况下,它是,因为函数只有在我设置表单中的值时才执行我也试过setAttribute,但它给出了相同的消息只有setAttribute


HTML
<section>
    <p>Set rotation Value!</p>
    <input id="rotationInput" type="text" />
    <button id="setRotation">Set Rotation</button>
</section>
...
<section>
        <img class="rotateimg" src="images/logo.scale-100.png" />
</section>

default.js

args.setPromise(WinJS.UI.processAll().then(function completed() {
...
   // Retrieve the button and register event handler. 
   var setRotation = document.getElementById("setRotation");
   setRotation.addEventListener("click", buttonClickHandler2, false);
};
...
function buttonClickHandler2(el) {
    var degrees = document.getElementById("rotationInput").value;
    document.getElementById("rotateimg").style.transform = "rotate(" + degrees + "deg)";

id和class不一样,看

<img class="rotateimg" src="images/logo.scale-100.png" />
应该

<img id="rotateimg" src="images/logo.scale-100.png" />

,或者

<img id="rotateimg" class="rotateimg" src="images/logo.scale-100.png" />