本帖最后由 newchilam 于 2012-05-16 22:25:31 编辑

解决方案 »

  1.   


    <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(&apos;"+ $(this).parent().attr('id') +"&apos;)' /> ";
    $(this).html(strhtml+'123');
    });</script>
    没问题啊,加123 是为了看效果。楼主 把你的问题,整理下 贴出来看看
      

  2.   

    表格代码不完整造成的。还有这里:
    ... + $(this).parent().attr('id') //td的父元素tr并没有id属性值
      

  3.   

    谢谢楼上的两位,问题找到了。把&apos;改成使用\'就好了。有高手说说这事怎么一回事吗?
      

  4.   

    &apos; 是xml符号不是标准合法的html符号,所以有些浏览器不支持,如果用的话可以用&#39;代替