我是法国人(对不起,我的英语很抱歉),这是Java开发中的网络开发新手。
我创建了一个名为“ manyStyles ”的函数。
此函数必须使用querySelector(“”)来获取元素,然后对之前获取的元素应用某种样式。这是一个非常简单的功能,仅供试用和学习。
该脚本的逻辑是:
-我在其中创建了4个变量,其中包含功能提示(“”);=>用户的价值存储在这四个变量中。
let askForElement= prompt("Type some selectors, with CSS synthax.. example:h1,h2.. #test(id) or .test(class)");
let askingHeight= prompt("Type some value for the height");
let askingWidth= prompt("Type some value for the width");
let askingBackgroundColor= prompt("Type some value for the background-color ex:red,green,blue, #66a ..");
-我在括号(elementGrab,elem_height,elem_width,element_bg_color)内声明带有4个参数(变量)的函数manyStyles => elementGrab用于捕获元素,就像我之前解释的一样,其他参数是用于样式的变量。
function manyStyles(elementGrab,elem_height,elem_width,element_bg_color){
let grabbedElement;
grabbedElement=document.body.querySelector(`${elementGrab}`);
document.body.grabbedElement.style=`height:${elem_height}px;width:${elem_width}px;background-color:${element_bg_color};`;
}
=>在body函数中,我只创建了一个名为“ grabbedElement”的变量,将要在下面的语句中被抓取的元素存储在其中。
最后,我用她的名字调用该函数,并在参数中放入4变量提示(在第一步中创建);
manyStyles(askForElement,askingHeight,askingWidth,askingBackgroundColor);
通常,该函数必须使用querySelcetor来获取元素,然后将其应用于样式。
但是由于某种原因是行不通的
看完整的代码更能说明..
谢谢
let askForElement= prompt("Type some selectors, with CSS synthax.. example:h1,h2.. #test(id) or .test(class)");
let askingHeight= prompt("Type some value for the height");
let askingWidth= prompt("Type some value for the width");
let askingBackgroundColor= prompt("Type some value for the background-color ex:red,green,blue, #66a ..");
function manyStyles(elementGrab,elem_height,elem_width,element_bg_color){
let grabbedElement;
grabbedElement=document.body.querySelector(`${elementGrab}`);
document.body.grabbedElement.style=`height:${elem_height}px;width:${elem_width}px;background-color:${element_bg_color};`;
}
manyStyles(askForElement,askingHeight,askingWidth,askingBackgroundColor);
您在内部创建了一个变量,并let grabbedElement
为其分配了grabped元素,但随后您没有使用它。应该是这样,您在其中更改了抓取元素。
grabbedElement.style=`height:${elem_height}px;width:${elem_width}px;background-color:${element_bg_color};`;
你想了解我styles
从document.body.grabbedElement
,但document.body.grabbedElement
不存在那里。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句