读书人

兼容有关问题 ie9,ff可用但在低版本

发布时间: 2012-05-21 18:04:41 作者: rapoo

兼容问题 ie9,ff可用,但在低版本的ie中无效,高手快看过来丫

HTML code
<td id="buttonRT2" button="RT2"><input class='btnAdd' width='42px' type='button' value='Add' onclick="changeCssForAdd('RT2')" /></td>



JScript code
$("td[button]").each(function () {var strhtml="<input  width='42px' type='button' value='Add' onclick='changeCssForAdd('"+ $(this).parent().attr('id') +"')' /> ";$(this).html(strhtml);//此处ie6,7,8中下抛出 synatax error  类似的还有使用beforehtml()时 });  });


[解决办法]
HTML code
<script src="http://code.jquery.com/jquery-latest.js"></script><table>    <tr>        <td id="buttonRT2" button="RT2">        <input class='btnAdd' width='42px' type='button' value='Add' onclick="changeCssForAdd('RT2')" />        </td>        </tr>    </table><script>$("td[button]").each(function () {var strhtml="<input  width='42px' type='button' value='Add' onclick='changeCssForAdd('"+ $(this).parent().attr('id') +"')' /> ";$(this).html(strhtml+'123');});</script>
[解决办法]
表格代码不完整造成的。

还有这里:
JScript code
... + $(this).parent().attr('id') //td的父元素tr并没有id属性值
[解决办法]
' 是xml符号不是标准合法的html符号,所以有些浏览器不支持,如果用的话可以用'代替

读书人网 >JavaScript

热点推荐