假设我有一个包含许多字符串的数组,名为"birdBlue","birdRed"和其他一些动物,如"pig1","pig2".
现在我运行一个遍历数组的for循环,并且应该返回所有的鸟.什么比较在这里有意义?
"birdBlue"是我的第一个想法但不起作用.有没有办法使用运营商*(或有类似的使用?
在这个使用JWT身份验证的exaple项目中,我们将了解如何仅允许经过身份验证的用户访问某些路由:
import { RouterConfig } from '@angular/router';
import { Home } from './home';
import { Login } from './login';
import { Signup } from './signup';
import { AuthGuard } from './common/auth.guard';
export const routes: RouterConfig = [
{ path: '', component: Login },
{ path: 'login', component: Login },
{ path: 'signup', component: Signup },
{ path: 'home', component: Home, canActivate: [AuthGuard] },
{ path: '**', component: Login },
];
Run Code Online (Sandbox Code Playgroud)
我想更进一步,并指出用户角色有什么"访问"路由 - 但我不知道如何将参数传递给canActivate AuthGuard(src).所以我想实现这样的目标(例如我有两个角色:Admin和Employee):
{ path: 'home', …Run Code Online (Sandbox Code Playgroud) 我无法onclick="location.href='link.html'"在Safari(5.0.4)中加载新页面.
我正在使用<select>和<option>HTML标签构建一个下拉导航菜单.我在点击菜单项后使用onClick处理程序加载新页面,但在Safari中没有任何反应.(我已经在FF和Opera中成功测试过了.)我知道Safari中有很多onClick错误,但我找不到解决这个特定问题的任何解决方案.
您可以在下面看到我的代码示例:
<select>
<option onclick="location.href='unit_01.htm'">Unit 1</option>
</select>
Run Code Online (Sandbox Code Playgroud)
和
<select>
<option onclick="location.href='#5.2'">Bookmark 2</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我不(并且不愿意)在我的HTML的head部分中嵌入任何javascript.我正在为不知道如何使用javascript的人开发页面 - 所以代码越简单越好.)
什么JavaScript代码会使菜单项在所有浏览器中都可点击?(请验证与IE的兼容性.)
function intFromBytes( x ){
var val = 0;
for (var i = 0; i < x.length; ++i) {
val += x[i];
if (i < x.length-1) {
val = val << 8;
}
}
return val;
}
function getInt64Bytes( x ){
var bytes = [];
var i = 8;
do {
bytes[--i] = x & (255);
x = x>>8;
} while ( i )
return bytes;
}
Run Code Online (Sandbox Code Playgroud)
我试图将javascript编号转换为字节数组,然后返回到数字.但是,上述功能会产生非常大数量的错误输出.
var array = getInt64Bytes(23423423);
var value = intFromBytes(array);
console.log(value); //Prints 23423423 - correct …Run Code Online (Sandbox Code Playgroud) 我有一个名为"file.txt"的文件,它通过添加行来更新它.
我正在通过这段代码阅读它:
$fp = fopen("file.txt", "r");
$data = "";
while(!feof($fp))
{
$data .= fgets($fp, 4096);
}
echo $data;
Run Code Online (Sandbox Code Playgroud)
并出现了大量的线条.我只是想回显文件的最后5行
我怎样才能做到这一点 ?
这file.txt是这样的:
11111111111111
22222222222
33333333333333
44444444444
55555555555555
66666666666
Run Code Online (Sandbox Code Playgroud) 我有一个带有显示设置的类,none我想在Javascript中将其设置为inline我知道我可以使用id来执行此id操作,但是使用类最干净的方法是什么?
我正在通过javascript创建SVG元素,它工作正常,但是当我创建一个文本svg元素并定义它的内容时,浏览器只是不渲染值,尽管我用firebug检查它时代码中的值.
代码是:
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('xlink','http://www.w3.org/1999/xlink');
svg.setAttribute('width','187');
svg.setAttribute('height','234');
var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
rect.setAttribute('width','187');
rect.setAttribute('height','234');
rect.setAttribute('fill','#fff');
rect.setAttribute('stroke','#000');
rect.setAttribute('stroke-width','2');
rect.setAttribute('rx','7');
var text = document.createElementNS('ttp://www.w3.org/2000/svg', 'text');
text.setAttribute('x', '10');
text.setAttribute('y', '20');
text.setAttribute('fill', '#000');
text.textContent = '2';
svg.appendChild(rect);
svg.appendChild(text);
var wp = document.getElementById('wrapper');
wp.appendChild(svg);
Run Code Online (Sandbox Code Playgroud)
这里是jsfiddle链接http://jsfiddle.net/sAhyC/ 如果您检查svg,您将看到文本元素的值,但浏览器不会呈现它.
谢谢
我的问题是
如何轻松安装docker以使其在终端中可用以及如何在osx上卸载docker?
在CSSLint (csslint.net)中,他们不建议使用id选择元素.我相信CSS Lint,因为它是由聪明的人写的,他们非常了解CSS.但我想知道这是什么原因?为什么选择id不好的东西?
有了这个页面:
<!DOCTYPE html>
<html>
<head>
<script>
"use strict";
var foo = 2;
delete foo;
</script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud)
Firebug控制台给出:
applying the 'delete' operator to an unqualified name is deprecated
>>> foo
ReferenceError: foo is not defined
foo
Run Code Online (Sandbox Code Playgroud)
但是这很成功:
>>> var bar = 2;
undefined
>>> delete bar;
true
Run Code Online (Sandbox Code Playgroud)
即使您注释掉delete foo;脚本没有中断,删除bar仍然是成功的,尽管它"是Global对象的属性,因为它是通过变量声明创建的,因此具有DontDelete属性 ":
>>> foo
2
>>> delete foo
false
>>> var bar = 2;
undefined
>>> delete bar
true
Run Code Online (Sandbox Code Playgroud)
是否可以启用"严格模式"; 在FireBug和Chrome的控制台?
javascript ×7
css ×2
angular ×1
comparison ×1
console ×1
csslint ×1
docker ×1
fopen ×1
html ×1
macos ×1
methodology ×1
onclick ×1
php ×1
roles ×1
safari ×1
strict-mode ×1
string ×1
svg ×1