Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向元素添加类javascript问题_Javascript_Jquery_Html_Css - Fatal编程技术网

向元素添加类javascript问题

向元素添加类javascript问题,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如果我在页面加载后使用javascript向元素添加类,那么与同一元素相关的属性会立即更新吗?使用jquery类似的方式: $(function(){ $('yourElemet').addclass('yourclass'); }) 在JavaScript中: <body onload="script();"> or document.onload = function ... or even window.onload = function .. 或 document.

如果我在页面加载后使用javascript向元素添加类,那么与同一元素相关的属性会立即更新吗?

使用
jquery
类似的方式:

$(function(){
$('yourElemet').addclass('yourclass');
})
在JavaScript中:

<body onload="script();">
or

document.onload = function ...
or even

window.onload = function ..

或
document.onload=函数。。。
甚至
window.onload=函数。。

是的,无论何时向元素添加新类,并且该类在引用的css文件中具有某些样式,都将应用该类

<p class="test">This is a test</p> 

.red {
    color: red;
}

$('.test').addClass('red');

这是一项测试 瑞德先生{ 颜色:红色; } $('.test').addClass('red');


请向我们展示一些“与同一元素相关的属性”代码?你有没有试着做你想做的事?失败了吗?向我们展示您的尝试并解释问题。