简体   繁体   English

无法从js设置样式

[英]Can't set styles from js

I don't know why but this js script don't work for me: 我不知道为什么但这个js脚本对我不起作用:

document.getElementById('logo').style.width="300px";

That what I have included in header: 这就是我在标题中包含的内容:

<link media="screen" href="/styles/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/js/libs.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

That is block I'm trying to set style for: 这是块我试图设置样式:

<a href="/index.php"><div id="logo">Some text</div></a>

You need to wrap it in something that instantiates it. 您需要将其包装在实例化它的内容中。

window.onload=function(){
document.getElementById('logo').style.width="300px";
};

Or in jQuery: 或者在jQuery中:

$(function(){
$('#logo').css( "width", "300" );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM