其中一个对象为null [英] Got null for one of the objects

查看:85
本文介绍了其中一个对象为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的.html文件中,我定义了2个对象如下:

In my .html file, I defined the 2 objects as below:

<div id="selectedListTable" class='styleTable2' style="height:220px;width:565px;" />
<div id="loader_" class='loader' style='display:none;' />



在js代码中,我得到v但v2为null


In the js code, I got v but v2 as null

var v = document.getElementById("selectedListTable");
var v2 = document.getElementById("loader_");     // v2 is null



我不知道为什么?如果你能指出原因,请感谢。



我尝试过:



其中一个对象为null


I don't know why? Appreciate if you can point out the reason.

What I have tried:

Got null for one of the objects

推荐答案

你的HTML有点混乱:

Your HTML is a bit of a mess:
<div id="selectedListTable" class='styleTable2' style="height:220px;width:565px;"/>
<div id="loader_" class='loader' style='display:none;' />

已过时且可能无效 - 似乎没有任何内容内容。除非是后续操作的目标,否则它们看起来毫无意义,除了占用空间。

is obsolete and likely invalid - and don't seem to have any content. Unless the target of a later operation, they seem rather pointless, except to take up space.

<div id="selectedListTable" class='styleTable2' style="height:220px;width:565px;"></div>
<div id="loader_" class='loader' style='display:none;'></div>

是应该看的样子 - 包含开始和结束元素之间的内容



如果您的浏览器无法解释这个问题,那么它可能没有两个不同的id =''属性。使用'/>'关闭元素不再是可接受的 - 尽管可能不会通过错误,具体取决于元素。例如,和< img src =>只是在没有反斜杠的情况下关闭。对于< input>也是如此。元素,而像< div>>需要结束< / div>>



假设它不是基于页面上其他地方的问题,请交换两个数据请求,看看你是否v2和v现在为空。

is how they should look - with content between the opening and closing elements

If, perchance, your browser has trouble interpreting this then it may not have the two id='' attributes distinct. The closing of an element with '/>' is no longer "acceptable" - although may not through an error, depending upon the element. For example, and <img src=""> simply closes without the backslash. This is also true for <input> elements whilst something like a <div>> requires a closing </div>>

Assuming it isn't based on a problem elsewhere on your page, swap the two data request and see if you v2 and v is now null.


这篇关于其中一个对象为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆