我不断碰到这个问题,每个人都在这里:a)想要用div包装HTML5语义标签,b)想要将类选择器应用于div而不是语义标签.就好像人们害怕出于某种原因将类打到语义标签上一样.
例如,我经常被告知这是"不正确的",
<body class="container">
<header class="row">
<div class="col-md-12"> ...
Run Code Online (Sandbox Code Playgroud)
这样的事情更可取,
<body>
<div class="container">
<div class="row">
<div class="col-md-12"> ...
Run Code Online (Sandbox Code Playgroud)
在这里,第一个例子我在h2标签中有列类
<div class="row">
<h2 class="col-4 feature">Featured Work</h2>
</div>
Run Code Online (Sandbox Code Playgroud)
但"正确"的方法是添加另一个div标签来应用该类,
<div class="row">
<div class="col-4 feature">
<h2>Featured Work</h2>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我理解这可能是基于意见的,但我发现在处理HTML5时,意见实际上很重要,因为几乎每个人都有问题,没有其他方法可以在没有意见的情况下敲定细节.
我想知道为什么第二个解决方案有效,但第一个解决方案有链接方法,但不起作用.
这种链式方法不起作用:
nopers = [5, 6, 7, 8, 9]
class Array
define_method(:trimy) do
self.shift().pop()
end
end
Run Code Online (Sandbox Code Playgroud)
当我测试它时,nopers.trimy(),它给出了一个未定义的错误消息."方法'pop'为1:Fixnum,在'block in'中"并且只执行.pop()方法,删除5.
但是,这个版本有效:
yuppers = [1, 2, 3, 4, 5, 6]
class Array
define_method(:trim) do
self.shift()
self.pop()
end
end
yuppers.trim()
Run Code Online (Sandbox Code Playgroud)
当我测试它时,yuppers给了我:[2,3,4,5]
我曾多次被告知不要选择<nav>&<body>等元素而是使用类选择器.例如," <nav>标签不是用于显示/样式目的,而是用于明确区分导航部分." 但这不是打败了语义元素的目的的一部分吗?
假设我只有一个项目符号导航列表,并且我将它们设置为水平,添加背景等,是否可以在课程中选择导航元素?
<nav class="navigation">
<ul class="links">
<li><a href="">Shop</a></li>
<li><a href="">Discounts</a></li>
<li><a href="">Profile</a></li>
<li><a href="">Blog</a></li>
</ul>
</nav>
Run Code Online (Sandbox Code Playgroud)
而且,如果你打算投票给我,请提供一个解释,而不是假设我可以直觉为什么你这样做.
鉴于n,我想创建一个从0到 的数组n:
10.make_array #=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Run Code Online (Sandbox Code Playgroud)
如果是负数,它也应该起作用n:
-10.make_array #=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]
Run Code Online (Sandbox Code Playgroud)
我已经编写了这段代码,但我认为我让它变得比必要的更复杂(它不适用于负数):
class Fixnum
define_method(:make_array) do
my_array = []
self.times() do |count|
self.>(0)
my_array.push(count)
end
my_array.push(self)
my_array
end
end
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法或捷径来做同样的事情,以及关于如何处理负数的任何建议?
我不明白为什么这个函数作为一个While循环,但不是一个For-Loop.我试图计数到10并在每次迭代时打印到控制台.
while循环:
function oneToTenW() {
var x = 0;
while(x < 10) {
x++;
console.log ("x is equal to " + x);
}
}
Run Code Online (Sandbox Code Playgroud)
for循环:
function oneToTenF() {
for(var x = 0; x < 10; x++);
console.log ("x is equal to " + x);
}
Run Code Online (Sandbox Code Playgroud)
当我调用While-Loop时,我得到了这个:
oneToTen();
x is equal to 1
x is equal to 2
x is equal to 3
x is equal to 4
x is equal to 5
x is equal to 6
x is equal …Run Code Online (Sandbox Code Playgroud) 这是代码:
<?php
$firstName = 'David';
$lastName = "Powers";
$title = '"The Hitchhiker\'s Guide to the Galaxy"';
$author = 'Douglas Adams';
$answer = 42;
$newLines = "\r\n\r\n";
$fullName = "$firstName $lastName |";
$book = "$title by $author";
$message = "Name: $fullName $newLines";
$message .= "Book: $book \r\n\r\n";
$message .= "Answer: $answer";
echo $message;
echo "Line 1\nLine 2";
Run Code Online (Sandbox Code Playgroud)
输出是一行,但当我查看源时,新行正在工作
Name: David Powers | Book: "The Hitchhiker's Guide to the Galaxy" by Douglas Adams Answer: 42Line 1 Line 2
Run Code Online (Sandbox Code Playgroud) 我无法通过使用添加来解决var total.它将与乘法运算符一起使用:var total = subtotal*sales_tax但不能使用+符号加法运算符:var total = subtotal + sales_tax.非常感激任何的帮助.
var calculate_click = function () {
var subtotal = parseFloat(document.getElementById("subtotal").value).toFixed(3);
var taxRate = parseFloat(document.getElementById("tax_rate").value).toFixed(3);
if (isNaN(subtotal) || isNaN(taxRate)) {
}
else {
var sales_tax = (subtotal * taxRate / 100);
parseFloat(document.getElementById("sales_tax").value = sales_tax.toFixed(3));
var total = subtotal + sales_tax;
parseFloat(document.getElementById("total").value = total.toFixed(3));
}
}
Run Code Online (Sandbox Code Playgroud) 该方法应该采用书籍的名称,并以适当的标题案例返回.所有我的规范pass()处理非字母字符,处理大写和混合大小写)除了最后一个返回特殊单词,如McDuff或McComb与大写第三个字母.有谁看到我做错了什么?并且,有没有办法简化这一点,使用手头的工具,而不是一些更高级别的快捷方式?
class String
define_method(:title_case) do
sentence_array = self.downcase.split
no_caps = ["a", "an", "the", "at", "by", "and", "as", "but", "or", "for", "in", "nor", "on", "at", "up", "to", "on", "of", "from", "by"]
sentence_array.each do |word|
if no_caps.include?(word)
word
else
word.capitalize!
end
sentence_array.first.capitalize!
# Manage special words
if (word.include?("mc"))
letter_array = word.split!("") # word with mc changed to an array of letters
if (letter_array[0] == "m") && (letter_array[1] == "c") # 1st & 2nd letters
letter_array[2].capitalize!
word = letter_array.join
end
end
end
sentence_array.join(" …Run Code Online (Sandbox Code Playgroud) ruby ×3
arrays ×2
css ×2
javascript ×2
class ×1
containers ×1
for-loop ×1
function ×1
html ×1
html5 ×1
nav ×1
php ×1
while-loop ×1