繁体   English   中英

javascript设置字体粗细:想要设置为粗体或正常无法正常工作

[英]javascript setting font-weight: want to set to bold or normal can't get it work

我似乎无法锻炼如何达到字体粗细。 设置,我想即时将设置更改为正常或粗体。 有任何想法吗?

HTML

<li onclick="showStuff(this)" id="tabs1" style="margin: -5px 0px 0px 0px; padding: 0px 10px; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: rgb(215, 215, 215); border-right-color: rgb(215, 215, 215); border-left-color: rgb(215, 215, 215); font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: bold; font-stretch: inherit; line-height: 1.7em; vertical-align: baseline; list-style: none; position: relative; z-index: 99; display: inline-block; float: left; bottom: 0px; background: none 0px 0px repeat scroll rgb(250, 250, 250);"
class="design1"><a style="margin: 0px; padding: 6px 1px 6px 2px; border: 0px; font-family: Verdana, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: bold; font-stretch: normal; line-height: 18px; vertical-align: baseline; outline: 0px; color: rgb(0, 0, 0); text-decoration: none; display: inline-block; text-align: center; min-width: 140px;"
<span style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;">
test1</span></a></li>

JavaScript的。

<script type="text/javascript">
function showStuff(element)  {
        document.getElementById("tabs1").style.marginTop = "-5px"; // works fine.

        document.getElementById("tabs1").style.fontWeight = "normal"; // doesn't work, tried various settings.
}

这是例子

<!DOCTYPE html>
<html>
<head>
<script     src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
    $("p:first").addClass("intro");
    });
});
</script>
<style>
.intro {
font-size: 150%;
color: red;
}
</style>
</head>
<body>

<h1>This is a heading</h1>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<button>Add a class name to the first p element</button>

</body>
</html>

您的html混乱了。 有一个未封闭的<a> -tag,其font-weight: bold; 并且它覆盖了font-weight: normal; #tabs1

删除font-weight: bold; <a> ,它将起作用。

 function showStuff(element) { document.getElementById("tabs1").style.marginTop = "-5px"; // works fine. document.getElementById("tabs1").style.fontWeight = "normal"; // doesn't work, tried various settings. } 
 <li id="tabs1" style="font-weight: bold;" class="design1"> <a href="#" onclick="showStuff(this)"> <span> test1 </span> </a> </li> 

暂无
暂无

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

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