编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

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

wxchong 2024-08-04 02:33:11 开源技术 33 ℃ 0 评论

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

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

append:function(){

return this.domManip(arguments,true,function(E){

if(this.nodeType==1) {

this.appendChild(E)

}

})}

JS代码:

function toPreCalc() {

if(validisOrNotSelected()) {

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

}else{

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

}

}

function validisOrNotSelected (){

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

return (count>0);

}

DOM结构:

<div 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/>

</div>

解决过程:

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

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

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

以下是修改后的DOM结构:

<div 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>

</div>

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表