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符号,所以有些浏览器不支持,如果用的话可以用'代替