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>元素已经注入了内容?