我在LI哪里给出了一个background-color: #ccc;,基本上我想在变量中获取背景颜色,现在我rgb(204, 204, 204) none repeat scroll 0% 0% / auto padding-box border-box在变量中获取这种格式,但我想要这种rgb(204, 204, 204)格式,这段代码有什么问题吗?
我尝试过:-
$('.response-box').on('click', '.color-box ul li', function() {
var colorBoxListBgColor = $(this).css('background');
console.log(colorBoxListBgColor);
});Run Code Online (Sandbox Code Playgroud)
.color-box ul li {
background-color: #ccc;
color: #ccc;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="response-box">
<div class="color-box">
<ul>
<li></li>
</ul>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
单击LI以检查控制台中的输出。
回答将不胜感激!
import html2canvas from 'html2canvas';
export default async function htmlToImg(id) {
applyShadow(false);
return await html2canvas(document.getElementById(id), {
scale: 1
})
.then(canvas => {
applyShadow(true);
let img = canvas.toDataURL('image/png')
console.log(img)
return img
});
}
Run Code Online (Sandbox Code Playgroud)
在这里我分享了我的代码。
我正在尝试将一些 html 节点转换为画布,然后将其转换为 i mage url。 但是,这是工作,但是,它给整个图像有时不同部分的50%,有时70%的的形象。html 很长,我认为它在完成将html 节点转换为 canvas或canvas.toDataURL('image/png')之前正在打印。
该函数是异步函数,因此它在完成转换完整的 html 之前记录日志。有什么办法可以解决吗?
请看一看
class Simulator {
constructor() {
this.gates = Array();
this.gates.push(new AndGate(200, 200));
}
initialize() {
let canvas = document.getElementById('board');
canvas.width = 800;
canvas.height = 500;
canvas.setAttribute("style", "border: 1px solid black");
this.gates.push(new AndGate(100, 100));
}
run() {
setTimeout(this.onLoop, 1000);
}
onLoop() {
for (let gate of this.gates) {
gate.render();
}
}
}
let sim = new Simulator();
sim.initialize();
sim.run();
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我的 TypeScript 类的 JS 转译版本在onLoop函数中引发错误。它报告TypeError: this.gates is undefined。但是,如果我访问sim(一个 Simulator 对象)并手动访问它定义的 gates 属性。我可以从控制台手动运行 onLoop 代码。
嗨,任何人都可以解释以下代码javascript不会抛出错误也不会显示任何内容
var text = 'outside';
function logIt() {
console.log(text);
var text = 'inside';
};
logIt();Run Code Online (Sandbox Code Playgroud)
我可以使用for循环而无需使用辅助方法来反转字符串。但是,如何保持字符串的原始顺序,空格和标点符号?
如果不使用reverse()helper方法,我可以反转字符串,但是无法保持单词和标点符号的顺序。
// Reverse preserving the order, punctuation without using a helper
function reverseWordsPreserveOrder(words) {
let reverse = '';
for (let i = words.length -1; i >= 0; i--) {
reverse += words[i];
}
return reverse;
}
console.log(reverseWordsPreserveOrder('Javascript, can be challenging.'))
// output-> .gnignellahc eb nac ,tpircsavaJRun Code Online (Sandbox Code Playgroud)
我希望结果是这样的:
// output-> tpircsavaJ, nac eb gnignellahc.
Run Code Online (Sandbox Code Playgroud) 在以下代码中,alert('Alert on btn is triggered') })即使在el event.preventDefault()的click处理程序中的此行之前调用了方法,也为什么会触发事件#btn。
同样,为什么onclick="alerted()不在div 上#btn或在#wrapdiv 上触发,而回调触发click随addEventListener触发一起触发。
var btn = document.getElementById('btn')
var wrap = document.getElementById('wrap')
btn.addEventListener('click', function() {
event.stopPropagation()
if (event.cancelable) {
event.preventDefault()
}
alert('Alert on btn is triggered')
})
function alerted() {
alert('Alerted fired')
}
wrap.addEventListener('click', function() {
alert(this.id)
alert(event.target.tagName + "#" + event.target.id)
})Run Code Online (Sandbox Code Playgroud)
#wrap {
padding: 20px;
border: 1px solid red;
}Run Code Online (Sandbox Code Playgroud)
<div id="wrap" onclick="alerted">
<button id="btn" …Run Code Online (Sandbox Code Playgroud)由于Math.sign()按照https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/sign接受数字参数或数字作为字符串,为什么给出以下结果,以及如何给出提供这些结果时发生了内部转换?
console.log(Math.sign([])); // 0
console.log(Math.sign([20])); // 1
console.log(Math.sign([20, 30, 40])) // NaNRun Code Online (Sandbox Code Playgroud)
我想检查 array1 中的值是否存在于 array2 中的对象中。
数组1:
[2,5,1]
Run Code Online (Sandbox Code Playgroud)
阵列2:
[
{ value: 1, name: 'Monday', isSelected: false },
{ value: 2, name: 'Tuesday', isSelected: false },
{ value: 3, name: 'Wednesday', isSelected: false },
{ value: 4, name: 'Thursday', isSelected: false },
{ value: 5, name: 'Friday', isSelected: false },
]
Run Code Online (Sandbox Code Playgroud)
我想实现的是检查array1针对array2已命名的属性value。如果对象中的array2值包含在 中array1,则该isSelected属性应更新为 true。我试过了:
this.setState(prevState => ({
...prevState,
array2: prevState.array2.map(el => {
if (el.value === array2) {
return { …Run Code Online (Sandbox Code Playgroud) function alertOuter() {
alert("outer alert")
}
function alertInner() {
alert("inner alert")
return
}Run Code Online (Sandbox Code Playgroud)
<div onclick="alertOuter()" style="padding:20px;background:red;">
<h1>Outer</h1>
<br/>
<button onclick="alertInner()">Inner</button>
</div>Run Code Online (Sandbox Code Playgroud)
我对onclick事件有两个函数调用。
我想alertOuter在单击按钮时阻止功能。但是,当我单击按钮时,它正在调用这两个函数。
alertOuter当单击按钮只想调用alertInner()函数时,我想阻止该函数
我怎样才能做到这一点?
包括有多少潜在选民年龄在 18-25 岁之间,有多少人在 26-35 岁之间,有多少人在 36-55 岁之间,以及每个年龄段有多少人实际投票。包含此数据的结果对象应具有 6 个属性。
var voters = [
{name:'Bob' , age: 30, voted: true},
{name:'Jake' , age: 32, voted: true},
{name:'Kate' , age: 25, voted: false},
{name:'Sam' , age: 20, voted: false},
{name:'Phil' , age: 21, voted: true},
{name:'Ed' , age:55, voted:true},
{name:'Tami' , age: 54, voted:true},
{name: 'Mary', age: 31, voted: false},
{name: 'Becky', age: 43, voted: false},
{name: 'Joey', age: 41, voted: true},
{name: 'Jeff', age: 30, voted: true},
{name: 'Zack', age: 19, …Run Code Online (Sandbox Code Playgroud)