【发布时间】:2010-01-22 13:55:18
【问题描述】:
我正在尝试在整个 ajax、整个页面中加载一个页面,并按照它在加载的页面中找到的格式来格式化我的页面。一些实际的练习。
ajax 调用的结果是一个包含页面 html 的字符串。
为了简单起见,我做了一个例子,一个包含页面本身的字符串。
<html>
<head>
<title>some test</title>
<style type="text/css">
.dv810 { height:810px; }
</style>
<script src="Scripts/Ref/jquery.js"></script>
<script type="text/javascript">
var sPage =
+'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ '\n<html xmlns="http://www.w3.org/1999/xhtml">'
+ '\n<head>'
+ '\n <title>some test</title>'
+ '\n <style type="text/css">'
+ '\n'
+ '\n #dvMain { height:830px; }'
+ '\n'
+ '\n </style>'
+ '\n</head>'
+ '\n<body>'
+ '\n <div class="container_12 mainContainer">'
+ '\n <div id="dvMain" class="dv810"></div>'
+ '\n <br/>'
+ '\n </div>'
+ '\n</body>'
+ '\n</html>';
alert('#dvMain: ' + $('#dvMain', $(sPage)).css('height'));
</script>
</head>
<body>
</body>
</html>
当我试图拉出一个 css 属性时,我遇到了这种尴尬的行为,比如高度:
- Firefox:#dvMain.height:810px
- Chrome:#dvMain.height:
- IE8:#dvMain.height:830px
- IE8(带有 IEtester):#dvMain.height:830px
- IE7(带有 IEtester):#dvMain.height:830px
- IE6(使用 IEtester):#dvMain.height:830px
看起来:
- IE 理解字符串中的 css,天知道怎么做(虽然这是一种奇怪的行为,但我有点喜欢它,虽然我认为我不会使用它),
- Firefox 的行为就像我认为的那样准确,从呈现页面的样式中获取类,
- Chrome 令我惊讶,不理解或不相关,呃,.. 好吧,什么都不显示
有谁知道为什么?
【问题讨论】:
-
我认为你必须关闭第二个 div:
<div id="dvMain" class="dv810">。
标签: jquery cross-browser jquery-selectors