jQuery笨拙的行为
我试图在整个ajax中加载一个页面,整个页面,并按照加载页面中的内容对我的页面进行格式化。某种程度上是一种实践活动 ajax调用的结果是一个包含页面html的字符串 为了简单起见,我举了一个例子,其中一个字符串包含页面本身的某些内容jQuery笨拙的行为,jquery,cross-browser,jquery-selectors,Jquery,Cross Browser,Jquery Selectors,我试图在整个ajax中加载一个页面,整个页面,并按照加载页面中的内容对我的页面进行格式化。某种程度上是一种实践活动 ajax调用的结果是一个包含页面html的字符串 为了简单起见,我举了一个例子,其中一个字符串包含页面本身的某些内容 <html> <head> <title>some test</title> <style type="text/css"> .dv810 {
<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.高度:830px
IE8带IEtester:dvMain。高度:830px
IE7带IEtester:dvMain.高度:830像素
IE6带IEtester:dvMain。高度:830px
看起来:
IE理解字符串中的css,他知道虽然这是一种奇怪的行为,但我有点喜欢它,尽管我认为我不会经常使用它,
Firefox的行为就像我认为的那样准确,从呈现页面的样式中获取类,
让我惊讶的是,Chrome不理解或不关联它,嗯,。。好吧,什么都不展示
有人知道为什么吗?
根据您的不同结果判断,我认为这是dom处理时间的问题,我想通过如下修改代码,结果是否有所不同:
var $sPage = $(sPage);
alert('#dvMain: ' + $('#dvMain', $sPage).css('height'));
或
我想你必须关闭第二个分区:。
$(sPage).ready(function(){
alert('#dvMain: ' + $('#dvMain', $(sPage)).css('height'));
});