向元素添加类javascript问题
如果我在页面加载后使用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.
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');
请向我们展示一些“与同一元素相关的属性”代码?你有没有试着做你想做的事?失败了吗?向我们展示您的尝试并解释问题。