如果我有一个JS对象,如:
var foo = { 'bar' : 'baz' }
Run Code Online (Sandbox Code Playgroud)
如果我知道foo有基本的键/值结构,但不知道键的名称,最简单的方法是什么?for ... in?$.each()?我希望有更好的东西......
我正在尝试将明星的BV颜色索引转换为明显的RGB颜色.除了查找表格和颜色渐变之外,似乎没有众所周知的算法可以做到这一点.
这是天文学家为一颗恒星指定其明显颜色的数字.热星(低BV)是蓝色/紫色,冷色星(高BV)是红色的,其间有白色/橙色星.

var t = 4600 * ((1 / ((0.92 * bv) + 1.7)) +(1 / ((0.92 * bv) + 0.62)) );
Run Code Online (Sandbox Code Playgroud)
如果将星型建模为黑体,则可以使用普朗克轨迹的数值近似来计算xy坐标(CIE色度)



// t to xyY
var x, y = 0;
if (t>=1667 && t<=4000) {
x = ((-0.2661239 * Math.pow(10,9)) / Math.pow(t,3)) + ((-0.2343580 * Math.pow(10,6)) / Math.pow(t,2)) + ((0.8776956 * Math.pow(10,3)) / t) + 0.179910;
} else if (t > 4000 && t <= 25000) {
x = ((-3.0258469 …Run Code Online (Sandbox Code Playgroud) 你有一个python脚本diagnosis.py,可以生成基于事件的实时数据.使用Node.js,您可以将其作为子进程启动并捕获其输出,然后使用Socket.IO将其发送到客户端并使用HTML呈现它.
服务器
var util = require('util'),
spawn = require('child_process').spawn,
ls = spawn('python', ['diagnosis.py']);
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(80);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
ls.stdout.on('data', function (gdata) {
socket.emit('news', gdata.toString());
});
});
Run Code Online (Sandbox Code Playgroud)
客户
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
var d = "";
var socket = io.connect('http://localhost');
socket.on('news', …Run Code Online (Sandbox Code Playgroud) algorithm semantic-web recommendation-engine machine-learning collective-intelligence
我在我的网站上使用自定义字体.我可以使用本地字体文件:
src: local('Ubuntu'), url('fonts/ubuntu.woff') format('woff');
Run Code Online (Sandbox Code Playgroud)
或者只是使用谷歌的:
src: local('Ubuntu'), url('http://themes.googleusercontent.com/static/fonts/ubuntu/v4/_xyN3apAT_yRRDeqB3sPRg.woff') format('woff');
Run Code Online (Sandbox Code Playgroud)
考虑到页面加载时间,哪个会更快?
我正在尝试为details元素实现jQuery回退.如果您从未听说过它,它基本上是一个Disclosure小部件.如果存在布尔属性open,则表示将向用户显示摘要和附加信息.如果该属性不存在,则仅显示摘要.以下HTML和CSS实现了这一点.
HTML
<!-- opened -->
<details open>
<summary>Summary</summary>
<p>Additional information</p>
</details>
<!-- closed -->
<details>
<summary>Summary</summary>
<p>Additional information</p>
</details>
Run Code Online (Sandbox Code Playgroud)
CSS
details summary ~ * {
display: none;
}
details[open] summary ~ * {
display: block;
}
Run Code Online (Sandbox Code Playgroud)
然后我添加了以下jQuery来open在summary单击元素时添加/删除属性.
jQuery的
$("summary").click(function() {
if ($(this).parent().attr("open")) {
$(this).parent().removeAttr("open");
} else {
$(this).parent().attr("open", "open");
}
});
Run Code Online (Sandbox Code Playgroud)
它会添加和删除open属性,但pChrome中的元素可见性不受影响.我究竟做错了什么?这是一个实例.
更新
open应该改为open="open"或者第一次不行.BoltClock还提供了另一种解决方案.但这不是主要问题.我遇到以下语法:
$('#sourcePane input:checked~img');
Run Code Online (Sandbox Code Playgroud)
我知道它选择了所有被检查的输入元素,也在id = sourcePane的元素下?对?
但是什么是~img?做什么〜
另外,HTML中的相应元素是
<div data-module="Sources" data-module-id="sourcePane">
为什么它不是id ="sourcePane"而是data-module-id ="sourcePane"?
在我读过的一些文章中,* {margin:0; padding:0;}不鼓励使用它,因为它会影响网站的性能.所以我转向了reset.css样式表.
但我想知道,它如何影响性能?
我希望在我的链接之间有彩色的vbars.最好的方法是什么?
案子
Home | About us | Contact
Run Code Online (Sandbox Code Playgroud)
垂直条需要是蓝色的.当我使用<div>蓝色标签时,我得到了这个:
Home
|
About us
|
Contact
Run Code Online (Sandbox Code Playgroud)