HREF修改该值会导致删除A标记内的嵌套元素

时间:2011-06-20 13:13:16

标签: jquery

通过jquery修改的以下A HREF元素删除嵌套的IMG元素。

<table id="newHead" width="90%" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC" style="display: none;border: 1px #000066 groove;">
    <tr height="25px"> 
        <td style="text-align: center;padding-left: 10px;"><strong style="white-space: nowrap; font-size: 12px; ">
        <font color="#000066"> Report</font></strong></td>
        <td> <a id="url" href="mmRep.do?action=getXLSummReport&reportId="><img align="right" hspace="850px" src="images/graph_bar/graph_Excel.jpg" width="25" height="25" border="0"> </a></td>
    </tr>
</table>

此jquery删除嵌套的IMG元素( )

var newurl = $("a#url").attr("href") + reportId;
$("a#url").attr("href",newurl);

在我修改href attr值后,html变得喜欢这个,img元素消失了

<td> 
<a id="url" href="mmRep.do?action=getXLSummReport&reportId=75">
</a>
</td>

1 个答案:

答案 0 :(得分:1)

Nope, it doesn't.

确保您的reportId包含整数,而不包含任何其他内容,例如引用"或单引号'

相关问题