欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jQuery错误:意外地调用了方法或属性访问的解决办法

程序员文章站 2022-06-26 09:40:07
问题现象:动态的改变html元素的内容时发生以下js报错: 报错位置:位于jquery.js的代码片段 append:function(){ return this.dommanip(argumen...

问题现象:动态的改变html元素的内容时发生以下js报错:

报错位置:位于jquery.js的代码片段

append:function(){

return this.dommanip(arguments,true,function(e){

if(this.nodetype==1) {

this.appendchild(e)

}

})}

jQuery错误:意外地调用了方法或属性访问的解决办法

js代码:

function toprecalc() {

if(validisornotselected()) {

$("#noticed").html("已勾选的产品");

}else{

$("#noticed").html("所有存在自营客户存续份额的产品");

}

}

function validisornotselected (){

var count = $("input[name='serial_no']:checked").length;

return (count>0);

}

dom结构:

<p align="center"><br/>

<tr>

<td width="80px" align="left" nowrap="nowrap" >预算日期:</td>

<td align="left" nowrap="nowrap" colspan="2">

<input type="text" id="precalcdate" name="precalcdate" class="wdate" onfocus="wdatepicker()" size="15" value="<%= precalcdate %>"/>

</td><br/>

</tr>

<tr>

<td width="80px" align="left" nowrap="nowrap" name="notice"><font>计算范围:</font></td>

<td align="left" nowrap="nowrap" id="noticed" name="notice"><font> </font></td>

</tr><br/>

</p>

解决过程:

查资料发现该问题的产生原因为:ie对动态append的内容有要求,需要将一个具有完整意义的html一起append到代码中 。

仔细检查发现,我的p里直接以tr元素开始了,这对于要求严格的ie来说显然不符合其规定,从严谨的角度来讲;tr元素必须是在table元素里才算是完整的html代码。

然后再tr外再加了一个table元素,问题得以完美解决~

以下是修改后的dom结构:

<p align="center"><br/>

<table>

<tr>

<td width="80px" align="left" nowrap="nowrap" >预算日期:</td>

<td align="left" nowrap="nowrap" colspan="2">

<input type="text" id="precalcdate" name="precalcdate" class="wdate" onfocus="wdatepicker()" size="15" value="<%= precalcdate %>"/>

</td><br/>

</tr>

<tr>

<td width="80px" align="left" nowrap="nowrap" name="notice"><font>计算范围:</font></td>

<td align="left" nowrap="nowrap" id="noticed" name="notice"><font> </font></td>

</tr><br/>

</table>

</p>