<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<title>myTest</title>
<script src="../js/jquery-1.3.2.min.js"></script>
<script>
$( function() {    $("p").attr("align",function(){return this.style});
}); });
</script>
</head>
<body>
<p style="center">nihao!</p>
</body>
</html>为什么运行完后 段落没有居中呢?

解决方案 »

  1.   

    $( function() { 
      $("p").css("text-align", "center"); 
    }); 
      

  2.   

    可能我说的还是不太明确,我的目的是想通过attr把<p>标签的style属性的值赋给<p>标签align属性,还得麻烦一下大家!
      

  3.   

    可能我说的还是不太明确,我的目的是想通过attr把 <p>标签的style属性的值赋给 <p>标签align属性,还得麻烦一下大家!
      

  4.   

    首先你style="center"本身就是错的如果写成sty="center",下面的就ok$("p").attr("align",function(){return $(this).attr("sty");}); 
      

  5.   

    style的值都是成对出现的如:style="color:red;"
      

  6.   

    style="center",这种写法是错误的。建议如下:$(function(){
    $("p").attr("align",function(){
    return this.id;
    })})
      <p id="center">testtesttesttesttesttest</p>
      

  7.   

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="utf-8"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <style>
    .img_bor
    {
    border: solid 5px red;
    }
    </style>
    <head> 
    <meta http-equiv="Content-Type" 
    content="text/html; charset=ISO-8859-1"> 
    <title>myTest </title> 
    <script type="text/javascript" language="javascript" src="http://static.cy-inc.com.cn/resources/js/jquery/jquery.20090603.js"></script><script> 
    $(function() { 
    $("p").attr("style","text-align: center"); 
    });  
    </script> 
    </head> 
    <body> 
    <img src="http://img0.cy-inc.com.cn/images/club2/club_gift_get.gif" title="http://img0.cy-inc.com.cn/images/club2/club_gift_get.gif"/>
    <p>ggggggggggggggggggggggggggg</p>
    </body> 
    </html> 
    -----------这样写是楼主想要的吗?
      

  8.   

    或者:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="utf-8"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <style>
    .img_bor
    {
    border: solid 5px red;
    }
    .txtalign
    {
    color: green;
    }
    </style>
    <head> 
    <meta http-equiv="Content-Type" 
    content="text/html; charset=ISO-8859-1"> 
    <title>myTest </title> 
    <script type="text/javascript" language="javascript" src="http://static.cy-inc.com.cn/resources/js/jquery/jquery.20090603.js"></script><script> 
    $(function() { 
    $("p").attr("class","txtalign"); 
    });  
    </script> 
    </head> 
    <body> 
    <p>ggggggggggggggggggggggggggg</p>
    </body> 
    </html> 
      

  9.   

    把jquery 的代码放到</body>后面dom没有注册,jquery找不到这个的。