html自动判断是否为空,确定/查找HTML DIV元素是否为空或未使用JavaScript

required maxlength="32"/>

我故意将元素留空,然后在用户单击菜单选项卡时将HTML注入其中.但是如果用户多次单击菜单项,我不想多次注入相同的HTML.为了避免这种情况,我希望代码确定元素是否已经注入了内容.我想使用Web API接口和JavaScript.使用.innerHTML添加内容

document.getElementById('UserRegistration').innerHTML=VariableWithRetreivedContent;

当用户单击“注册”菜单选项卡时,将运行一个函数.我已经尝试使用它来确定是否已添加内容,但它不起作用:

function goToRegistration(ElmtToGoTo,FileToGet) {

//Use getElementById to get info from the ElmtToGoTo DIV

// and put info into the el variable

var el = document.getElementById(ElmtToGoTo);

alert(el.value);

// If element is already filled quit

if (el.value === undefined || el.value === "")

{

/To Do: Quit Here

};

//To Do: Get content and put it into DIV element

};

我得到的是未定义DIV是否有任何内容.如何测试< div>元素已经注入了内容?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值