我想通过 javaScript 访问类“pdocCover”来设置正文的宽度和高度。我该怎么办?
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by PubliForge, $Date: 2012/02/03 12:17:54 $ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Content-Language" content="en"/>
<title>Couverture</title>
<link rel="StyleSheet" href="Css/reset.css" type="text/css"/>
<link rel="StyleSheet" href="Css/publidoc.css" type="text/css"/>
<link rel="StyleSheet" href="Css/main.css" type="text/css"/>
</head>
<body class="pdocCover">
<div>
<img src="Images/9782919504060.png" alt="Couverture"/>
</div>
</body>
</html>
最佳答案
通过使用 jQuery
$(".pdocCover").css("height","500px");
$(".pdocCover").css("width","500px");
通过使用 JavaScript
document.getElementsByClassName('pdocCover').style.height="500px;"
document.getElementsByClassName('pdocCover').style.width="500px;"
关于javascript - 如何通过javaScript访问类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11131382/