通过JavaScript做CSS [英] Doing CSS via JavaScript
问题描述
我想通过JavaScript做一行CSS: -
p {margin:0px; }
如何解决这个问题?
非常感谢提前,
亚伦
>我想通过JavaScript做一行CSS
做是什么?意思?这需要插入哪里?可以将
插入到html doc的head元素中吗?
Peter
>>我想通过JavaScript做一行CSS
做是什么?是什么意思?
这需要插入哪里?是否可以将
插入到html doc的head元素中?
我在IFrame中有一个文档,并希望修改其CSS设置以使
段落的边距为零。
Aaron
Aaron Gray写道:
我想通过JavaScript做一行CSS: -
p {margin:0px; }
我该怎么做?
在JavaScript中改变单个元素的样式很容易,但在
中
为了做你想做的事,你必须找到所有的p元素和
将样式应用到返回的每个元素。
Something喜欢(未经测试)
var paras = document.getElementsByTagName(''p'');
for(var i = paras.length -1; i> =); --i)
{
paras [i] .style.margin =''0px'';
}
-
Ian Collins。
Hi,
I have a single line of CSS that I want to do via JavaScript :-
p { margin: 0px; }
How do I go about this ?
Many thanks in advance,
Aaron
> I have a single line of CSS that I want to do via JavaScript
What does the "do" mean? Where does this need to be inserted? Can it be
inserted into the head element of your html doc?
Peter
>> I have a single line of CSS that I want to do via JavaScript
What does the "do" mean?
Where does this need to be inserted? Can it be
inserted into the head element of your html doc?
I have a document in an IFrame and want to modify its CSS setting to make
paragraphs have zero margins.
Aaron
Aaron Gray wrote:Hi,
I have a single line of CSS that I want to do via JavaScript :-
p { margin: 0px; }
How do I go about this ?
It''s easy to change the style on a single element in JavaScript, but in
order to do what you want, you will have to find all the p elements and
apply the style to each element returned.
Something like (untested)
var paras = document.getElementsByTagName(''p'');
for( var i = paras.length-1; i >= ); --i )
{
paras[i].style.margin = ''0px'';
}
--
Ian Collins.
这篇关于通过JavaScript做CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!