题
更多是出于好奇,但我想知道如何将if语句重构为更清晰/更不易碎的东西.从我读过的,多态可能有用吗?
在示例中,我只想返回第一辆车,如果color:'red'是真的话.
CoffeeScript的
example: () ->
cars = [{color:'red', reg:'111'},{color:'blue', reg:'666'}]
if cars[0].color is 'red'
then cars[0]
else cars[1]
Run Code Online (Sandbox Code Playgroud)
使用Javascript
example: function() {
var cars = [{color:'red',reg:'111'},{color:'blue',reg:'666'}];
if (cars[0].color === 'red') {
return cars[0];
} else {
return cars[1];
}
}
Run Code Online (Sandbox Code Playgroud)
我理解这个问题可能由于模糊性而被关闭或移动
我想仅在用户点击标签按钮时才在Tumblr博客上显示标签列表.为此,我使用这个HTML和jQuery.
HTML
<span class="tags-link">Tags</span>
<ul class="tags">
<li> <a href="{TagURL}">{Tag}</a> </li>
</ul>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$(document).ready(function(){
$(".tags-link").click(function() {
$(".tags").slideDown(700, function(){
//end animation
});
});
});
Run Code Online (Sandbox Code Playgroud)
每次我点击页面上的.tags-link每一个.tags显示,我只想要显示用户点击的帖子.我最近开始学习jQuery,我在这里有点迷失......
我正在使用Google Feed API从tumblr feed 中提取博客条目。
我已经能够提取内容,但输出带有 html 标签,如下所示:
<p>I remember one day asking one of my mentors James if he ever got nervous around people. James replied, “Only when I need something from them.”</p>
代码很简单,如下:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://adriennetran.tumblr.com/rss");
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
window.content = document.createTextNode(entry.content); …Run Code Online (Sandbox Code Playgroud) 容器只有屏幕高度的3/4左右,这与子元素的高度不同.
这是为什么?
我试图给容器和身体一个,min-height: 100%但这不起作用.即使!important
我不使用bootstrap,只是简单的html和CSS.
任何帮助非常感谢!
编辑:更改正文或html高度不起作用.这打破了页面.
我有一个带有以下CSS的正文:
body {
background-image: url("../img/1.png");
background-repeat: repeat;
background-size: cover;
font-family: "Raleway", sans-serif;
font-size: 20px;
font-weight: 300;
}
Run Code Online (Sandbox Code Playgroud)
容器有这个CSS规则:
.container {
width: 900px !important;
margin: auto;
padding-left: 20px;
padding-right: 20px;
background-color: rgba(255, 255, 255, 0.3);
height: 100% !important;
}
Run Code Online (Sandbox Code Playgroud)
我的标记看起来像这样:
<body>
<div class="container">
<div class="header">
<div class="lang">
<ul class="languages">
<li>DE</li>
<li>FR</li>
</ul>
</div>
<img src="img/header/royalpool.png" alt="" class="logo-royal"/>
<img src="img/header/bluetech.png" alt="" class="logo-bluetech"/>
<div class="lang">
<ul class="languages">
<li>Kontakt</li>
<li>Downloads</li>
<li>Händler</li>
</ul>
</div>
<ul …Run Code Online (Sandbox Code Playgroud)