开发者

jQuery 1.3.2 adds sizset='' sizcache='' attributes on IE when I use .html() function

开发者 https://www.devze.com 2022-12-14 10:34 出处:网络
When I do $(\'div#tborder\').html() I get following: <DIV id=tborder style=\"BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid;

When I do $('div#tborder').html() I get following:

<DIV id=tborder style="BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; 
DISPLAY: block; FONT-SIZE: 12px; BORDER-LEFT开发者_如何学运维: #000 1px solid; 
BORDER-BOTTOM: #000 1px solid; FONT-FAMILY: Arial; 
TEXT-ALIGN: left" sizcache="9" sizset="124">Some Text </div>

See the additional sizcache and sizset attributes are set. How can I get rid of these? This is a known bug in jQuery1.3.2 according to this. Please see the comments in this article as well.

Original Code:

<DIV id=tborder style="BORDER: #000 1px solid;  
DISPLAY: block; FONT-SIZE: 12px; FONT-FAMILY: Arial; 
TEXT-ALIGN: left">Some Text </div>


Do you really need to use html? It seems to return a lot of useless attributes along with sizcache and sizset. If all you want is the text, then have a look at text() instead.


Though not good solution but I've temporarily hacked it using javascript RegExp function.


If you have a javascript error in your page, you will see these do not always get removed by the sizzle engine. For instance, if you put a reference to a method/function in the window opener pages javascript function, and you did not open the page from that opener, you will see these.

for instance in this code, the opener is not present:

if (self.opener.panelNotes)
{
    self.opener.__doPostBack("panelNotes", "");
};

because I directly opened the window, and it was not opened by another window so no opener exists. This gives a javascript error on the page

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; MDDR; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0) Timestamp: Thu, 6 May 2010 15:15:16 UTC

Message: 'self.opener.panelNotes' is null or not an object Line: 278 Char: 9 Code: 0 URI: http://localhost/prototype/Apps/SmartPrototype/Js/MarkPrototype.js


Put quotation marks around the id value. id=tborder -> id="tborder"
Also make both div lower case. <DIV> </div> -> <div></div>

If those two things don't work. Then use removeAttr().html().

$( "#tborder" ).removeAttr("sizcache").removeAttr( "sizset" ).html();
0

精彩评论

暂无评论...
验证码 换一张
取 消