一个不知道为什么的问题:
<head>
<title>practice.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
/*圆角*/
$(function() {
$("#op").each(function(){/*setting div auto grouth*/
var h1 = $(this).height();
alert(h1);
var h2= this.scrollHeight;
if(h1>h2){
$(this).height(h1);
return false;
}
});
});
</script>
<style type="text/css">
@IMPORT url("basic.css");
body {
background-image:url(image/bodyBg.gif) ;
height:100%;
text-align:center;
}
#op {
background-color: gray;
filter: Alpha(opacity=30);
-moz-opacity:.3;
opacity:0.3;
margin:0 auto;
width:300px;
height:100px;
}
#text {
padding-top:10px;
padding-right:10px;
word-wrap:break-word;
}
h1, h6{
font-size:20px;
color:block;
text-align: right;
padding-right:10px;
}
h6{
font-size:15px;
}
#logo img{
position:absolute;
top:10px;
left:21px;
}
</style>
</head>
<body>
<div id="logo">
<img src="image/logo.png"></img>
</div>
<div id="op">
<div id="text">
<h1>Ni Hao world</h1>
<h6>© 2011</h6>
<p>
assssssdfffsdgfjksdgajkdfjkakjdsfasdjk
dasgafgffahhhhhhhhhhhffffhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
</p>
</div>
</div>
</body>
在ff中测试 加了alert(h1) div的高度才会变 帮忙看看。
<head>
<title>practice.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
/*圆角*/
$(function() {
$("#op").each(function(){/*setting div auto grouth*/
var h1 = $(this).height();
alert(h1);
var h2= this.scrollHeight;
if(h1>h2){
$(this).height(h1);
return false;
}
});
});
</script>
<style type="text/css">
@IMPORT url("basic.css");
body {
background-image:url(image/bodyBg.gif) ;
height:100%;
text-align:center;
}
#op {
background-color: gray;
filter: Alpha(opacity=30);
-moz-opacity:.3;
opacity:0.3;
margin:0 auto;
width:300px;
height:100px;
}
#text {
padding-top:10px;
padding-right:10px;
word-wrap:break-word;
}
h1, h6{
font-size:20px;
color:block;
text-align: right;
padding-right:10px;
}
h6{
font-size:15px;
}
#logo img{
position:absolute;
top:10px;
left:21px;
}
</style>
</head>
<body>
<div id="logo">
<img src="image/logo.png"></img>
</div>
<div id="op">
<div id="text">
<h1>Ni Hao world</h1>
<h6>© 2011</h6>
<p>
assssssdfffsdgfjksdgajkdfjkakjdsfasdjk
dasgafgffahhhhhhhhhhhffffhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
</p>
</div>
</div>
</body>
在ff中测试 加了alert(h1) div的高度才会变 帮忙看看。
解决方案 »
- 调用window.onbeforeunload事件,点击翻页事件时,弹出2次窗口?
- js的onkeydown事件
- 请大家解决这个jQuery的问题
- 还是一个关于event.srcElement在ff兼容的问题
- 问一个比较猪头的问题
- 网页由三部分组成, 其中中间的宽度定死, 左右两部分的宽度成1:5的关系。
- js如何在跳转之前执行完所有代码
- 如何在没有提交页面的情况下,取“列表/菜单”的值
- BubbleInDiamond(钻石里的泡泡) ,请注意,为了将剩余的140分,给你,请答复此帖(duoergun)
- 如何判断我的提交页中的内容是否为数字类型???
- $(this) 如何获取它下面的其他元素呢?
- 关于JQury:eq获取对象时与$(this)对象,两个Jquery对象对比的问题 求高手讲解
$(document).ready(function () {
//你的就是代码
});
那样肯定不会循环啊,把id换成class什么的
$(".test").each(function(){
})
var h1 = $(this).height();
alert(h1);
var h2= this.scrollHeight;
if(h1>h2){
$(this).height(h1);
return false;
}
});
$(function() { = $(document).ready(function () { 是缩写
$(document).ready( function() {
$("#op").height($("#text").outerHeight());
});
$("#op").each(function(){
//这里执行的是什么?也就是这么写有什么含义?是把#op里面的所有元素都遍历吗?怎么查看遍历到了什么?
});
})
$("#op").children()才是它的子元素 。
<blockquote>一段文字(可能长也可能短)</blockquote>
</div>怎么样能使得文字的长短 div的 height 也能跟着改变呢?
$(function() {
$("#op").each(function() {
var h1 = $(this).height();
var h2 = this.scrollHeight;
if (h2 > h1) {
$(this).height(h2);
return false;
}
});
});
下载地址
$(".test").each 意思是对 $(".test")返回的JQUERY 元素对象数组 。
当然你写成ID也可以。。只是只有一个元素对象而已。。