做getElementsByClassName
(等类似的功能getElementsByTagName
和querySelectorAll
)的工作方式相同getElementById
,还是他们返回元素的数组?
我问的原因是因为我试图改变所有元素的样式getElementsByClassName
.见下文.
//doesn't work
document.getElementsByClassName('myElement').style.size = '100px';
//works
document.getElementById('myIdElement').style.size = '100px';
Run Code Online (Sandbox Code Playgroud) 我在表格中有一个复选框列表.(行中的一些CB)
<tr><td><input type="checkbox" class="custom_image" value="1" id="CB1" /><label for='CB1'> </label></td></tr>
<tr><td><input type="checkbox" class="custom_image" value="2" id="CB2" /><label for='CB2'> </label></td></tr>
<tr><td><input type="checkbox" class="custom_image" value="3" id="CB3" /><label for='CB3'> </label></td></tr>
<tr><td><input type="checkbox" class="custom_image" value="4" id="CB4" /><label for='CB4'> </label></td></tr>
Run Code Online (Sandbox Code Playgroud)
我想用一对自定义的开/关图像替换复选框图像,我想知道是否有人更好地理解如何使用CSS执行此操作?
我找到了这个"CSS忍者"教程,但我不得不承认我觉得它有点复杂. http://www.thecssninja.com/css/custom-inputs-using-css
据我所知,你被允许使用伪类
td:not(#foo) > input[type=checkbox] + label
{
background: url('/images/off.png') 0 0px no-repeat;
height: 16px;
padding: 0 0 0 0px;
}
Run Code Online (Sandbox Code Playgroud)
我的期望是,通过添加上面的CSS,复选框至少会默认显示处于OFF状态的图像,然后我会添加以下内容以获得ON
td:not(#foo) > input[type=checkbox]:checked + label {
background: url('/images/on.png') 0 0px no-repeat;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我似乎错过了某个关键步骤.我试图使用自定义CSS3选择器语法来匹配我当前的设置 - 但必须丢失一些东西(如果重要的话,图像大小为16x16)
http://www.w3.org/TR/css3-selectors/#checked
编辑:我在教程中遗漏了一些内容,他将图像更改应用于标签而不是输入本身.我仍然没有在页面上获得预期的交换图像以获得复选框结果,但我认为我更接近了.
我想匹配的数小于或等于100,它可以是内0-100任何东西,但是该正则表达式不应该匹配为一些其大于100如120,130,150,999,等等.
使用div或canvas,目标是用图像/屏幕截图完全填充设备框架,但又不会溢出框架。
屏幕截图1展示了紧贴框架内的图像。屏幕截图2说明了图像渗漏到框架之外的情况。
第一个挑战是图像/屏幕截图的宽高比可能会有所不同,即可能会使用不同尺寸的图像。例如,一个图像可以是1242x2688,而另一图像可以是1440x2960。无论宽高比如何,屏幕截图都应填充框架,但不会流过其边缘。
第二个挑战是它们在CSS中的缩放比例通常transform: scale(x)
约为25%,浏览器的舍入行为在此比例下会产生像素大小的间隙。但是,当比例恢复到100%时,这些差距将消失。
我们尝试了两种选择。两者都有缺陷。
两者都使图像/屏幕截图成为帧div的子div。
选项1:填充值
我们使用“ padding”值来调整子div的宽度,高度和位置(即屏幕截图),以使其适合其父框架。但是,具有不同长宽比的图像可能会渗漏到框架之外或无法填满框架。
选项2:剪切路径
我们使用剪切路径来表示框架内的区域,但有时会出现间隙,具体取决于CSS缩放值。我们不能允许差距。
下面的代码和Codepen中说明了间隙问题。
还有其他选择吗?
Codepen(说明差距):https ://codepen.io/anon/pen/yWXvJE
.colorClassProxy {
display: none
}
.itemBox, .itemBox > * {
position: absolute;
box-sizing: border-box;
}
.backgroundColorBox, .backgroundGraphicBox, .foregroundBox, .frameBox {
width: 100%;
height: 100%;
background-size: contain;
background-color: transparent;
background-position: center;
background-repeat: no-repeat;
pointer-events: none;
}
Run Code Online (Sandbox Code Playgroud)
<div class="itemBox graphic" id="NZW2Hmn4nVgb" style="width: 173px; height: 364px; top: 86px; left: 111px;"><div class="backgroundColorBox" style="width: 163px; height: 335px; top: 17px; left: 4px; -webkit-mask-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%2241.7%20142.4%201445.2%202965.9%22%20preserveAspectRatio=%22none%22%3E%3Cpath%20d=%22M1359.3,3105.3h-1190c-68.8,0-124.6-53.2-124.6-118.9V264.3c0-65.7,55.8-118.9,124.6-118.9h1190%20%20c68.8,0,124.6,53.3,124.6,118.9l0,2722.1C1484,3052.1,1428.2,3105.4,1359.3,3105.3L1359.3,3105.3z%22%20style=%22fill:%20white;%20stroke:%20white;%20stroke-width:%206;%22/%3E%3C/svg%3E"); background-size: cover;"></div><div class="backgroundGraphicBox" …
Run Code Online (Sandbox Code Playgroud)我试图理解如何按随机顺序对数组进行排序.所以,我找到了以下代码:
var as = ["max","jack","sam"];
var s = as.sort(func);
function func(a, b) {
return 0.5 - Math.random();
}
console.log(s);
Run Code Online (Sandbox Code Playgroud)
我的主要问题是为什么他们使用0.5而不是另一个数字?和它如何工作,请尽量做到简单我在JavaScript是新的,我用这些东西奋斗
在MySQL 5.6数据库,我有表tablename
已经(包括人)三TEXT
列:col_a, col_b, col_c
。
我想从这三列中提取至少5个字符的所有唯一单词(单词之间用空格分隔)。“单词”是指任何非空格字符字符串,例如“ foo-123”和“ 099423”都是单词。这些列都是utf8格式的InnoDB列。
是否有单个查询可以执行此操作?
编辑:根据要求,下面是一个示例:(在实际数据中,col_a,col_b和col_c是TEXT字段,可能包含大量单词。)
select id, col_a, col_b, col_c from tablename;
id | col_a | col_b | col_c
----|--------------------|----------------|----------------------
1 | apple orange plum | red green blue | bill dave sue
2 | orange plum banana | yellow red | frank james
3 | kiwi fruit apple | green pink | bill sarah-jane frank
expected_result: ["apple", "orange", "banana", "fruit",
"green", "yellow", "frank", "james", "sarah-jane"]
Run Code Online (Sandbox Code Playgroud)
我不在乎结果的顺序。谢谢!
编辑:在上面的示例中,所有内容都是小写字母,因为这就是我将所有内容存储在与该问题相关的真实表中的方式。但是,为了争辩,如果它确实包含一些大写字母,我希望查询忽略大写字母(这是我的数据库配置的设置)。
EDIT2:如果有帮助,则所有文本列上均具有FULLTEXT索引。
EDIT3:这是创建示例数据的SQL: …
每次调用时Element.getClientRects()
,它都会返回一个只有一个DOMRect
对象的集合.
什么时候Element.getClientRects()
返回多个DOMRect
对象的集合?
function handleClick() {
console.log(event.target.getClientRects())
}
Run Code Online (Sandbox Code Playgroud)
<ul
style="border: 1px solid black;"
onclick="handleClick()"
>
<li>Click the text to see in console</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
以下是我的server.js
代码的MCVE :
let fs = require('fs');
let http = require('http');
http.createServer((req, res) => {
// Handles GET requests
if(req.method == 'GET') {
let file = req.url == '/' ? './index.html': '/login.html'; // just an example
fs.readFile(file, (err, data) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
});
}
// Handles POST requests
else {
read(status => {
if(status) {
res.writeHead(302, {
'Location': 'http://localhost:8000/login.html',
'Content-Type': 'text/html'
});
res.end();
console.log('Redirected!');
}
});
}
}).listen(8000);
// In my actual script, the `read` function …
Run Code Online (Sandbox Code Playgroud) 该process.cpuUsage()
函数显示一些奇怪的微秒值。如何以百分比获取cpu使用率?
从文件对话框中选择文件并单击“确定”后,如何改进此代码以消除无响应/页面延迟?
我一直在测试大小约为 50-100 KB 的文件
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
Run Code Online (Sandbox Code Playgroud)
<input type="file" id="files" name="files[]" multiple …
Run Code Online (Sandbox Code Playgroud)