运行我的应用程序时出现JS错误 [英] JS errors when i am running My Application

查看:97
本文介绍了运行我的应用程序时出现JS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我运行Web应用程序时,在某些页面中,它会给出 htmlfile无效参数的异常,并在js文件中显示错误,如此处所述

Hi,

When i am running my Web Application, in some pages it is giving an Exception as htmlfile invalid argument and it is showing a error in js file in the code as mentioned here

appendElementToFormOrBody: function(element) {
        /// <summary>
        /// Tries to append an element to the current form. If no form exists, the element will be appended to the body element.
        /// </summary>
        /// <param name="element" type="Object">The element to append.</param>
        if (document.forms && document.forms[0]) {
            document.forms[0].appendChild(element);
        } else {
            document.body.appendChild(element);
        }
    }


-------------------------------------------------- --------------------------
我需要解决此问题..


----------------------------------------------------------------------------
I need help in this issue..

推荐答案

我认为元素变量未使用HTML DOM对象正确声明/初始化.只能将HTML DOM对象传递给appendChild方法.

我认为,如果您喜欢以下内容,它将可以正常工作.
I think the element variable is not declared/initialized properly with a HTML DOM object. Only HTML DOM objects can be passed in to the appendChild method.

I think if you do like below, it will work.
var element = document.getElementsByName("element")[0]; 



这是执行此操作的原始代码.我已经在IE8和Firefox中对其进行了测试.



Here is a crude code doing the same. I have tested it in both IE8 and Firefox.

<html>
<head>
</head>
<script>
function myFunction() {
	var myElem = document.getElementsByName("testElem")[0];
	myElem.value += "test ";
	var p = document.createElement("p");
	p.innerHTML = "test test test"
	if (document.forms && document.forms[0]) {
	   document.forms[0].appendChild(myElem);
	   document.forms[0].appendChild(p);
	} 
	else {
	   document.body.appendChild(myElem);
	   document.body.appendChild(p);
	}
}
</script>
<body>
<form name="myForm">
<input type="text" name="testElem" />
test
</form>
</body>
</html>


这篇关于运行我的应用程序时出现JS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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