CSS和JavaScript [英] CSS and JavaScript
问题描述
如果我尝试使用JavaScript更改输入TEXT框中的字体,我该怎么做?b
$ b document.forms [x] .elements [y] .class = fontSize;
fontSize是一个CSS类,如果我硬编码但无法正常工作
动态地如上所述
if I am trying to change font in an input TEXT box using JavaScript how do I
do it?
document.forms[x].elements[y].class=fontSize;
fontSize being a CSS class, works if I hard code it in but will not work
dynamicly as above
推荐答案
标记属性称为类
相关的脚本属性称为className。他们必须这样做,因为等级是等级。是脚本中的保留名称,因此可以将
搞砸了。
同一类型的另一个差异,出于同样的原因:
< label for =" b01">
但
labelObject.htmlFor
此外,className需要字符串参数,而不是对象。
另外fontSize等于font-size的驼峰形式。风格
属性迟早会在某处打到你的代码。
将所有内容整合在一起:
文件。 forms [x] .elements [y] .className =" specialFontSize";
tag attribute is called "class"
the relevant scriptable property is called className. They have to do
it because "class" is a reserved name in script, so could screw the
things up.
Another discrepancy of the same kind and for the same reason:
<label for="b01">
but
labelObject.htmlFor
Also className takes string argument, not an object.
Also "fontSize" is equal to the camelized form of "font-size" style
attribute wich will hit your code somewhere sooner or later.
Puting all together:
document.forms[x].elements[y].className = "specialFontSize";
NEWS写道:
NEWS wrote:
如果我尝试使用JavaScript更改输入TEXT框中的字体我该如何做?
document.forms [x] .elements [y] .class = fontSize;
fontSize是一个CSS类,如果我硬编码但无法正常工作
如上所述
if I am trying to change font in an input TEXT box using JavaScript how do I
do it?
document.forms[x].elements[y].class=fontSize;
fontSize being a CSS class, works if I hard code it in but will not work
dynamicly as above
我从中得到了一个含糊不清的信息,所以我只需要b $ b覆盖它们。
1.你只是在尝试改变元素的类?在这种情况下:
document.forms [" x"]。elements [" y"]。className =" fontSize";
2.在css中有一个font-size属性,如果那就是你想要的那么b $ b影响那么:
文件。形式[" x"]。elements [" y"] .style.fontSize =" 12pt";
There is an ambiguous messages I''m getting from this, so I''ll just
cover them all.
1. Are you just trying to change the element''s class? In that case:
document.forms["x"].elements["y"].className = "fontSize";
2. There is a font-size property in css, and if that''s all you want to
affect then:
document.forms["x"].elements["y"].style.fontSize = "12pt";
" web.dev" <我们******** @ gmail.com>在消息中写道
news:11 ********************** @ g47g2000cwa.googlegr oups.com ...
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
NEWS写道:
NEWS wrote:
如果我尝试使用JavaScript更改输入TEXT框中的字体我是怎么做的?
document.forms [x] .elements [y] .class = fontSize;
fontSize是一个CSS类,如果我硬编码但无法正常工作
动态地如上所述
if I am trying to change font in an input TEXT box using JavaScript how
do I
do it?
document.forms[x].elements[y].class=fontSize;
fontSize being a CSS class, works if I hard code it in but will not work
dynamicly as above
我从中得到了一个含糊不清的信息,所以我只是将它们全部覆盖。
你只是想改变元素的类吗?在这种情况下:
document.forms [" x"]。elements [" y"]。className =" fontSize" ;;
2.有一个css中的font-size属性,如果那就是你想要影响的那些:
document.forms [" x"]。elements [" y"]。 style.fontSize =" 12pt";
There is an ambiguous messages I''m getting from this, so I''ll just
cover them all.
1. Are you just trying to change the element''s class? In that case:
document.forms["x"].elements["y"].className = "fontSize";
2. There is a font-size property in css, and if that''s all you want to
affect then:
document.forms["x"].elements["y"].style.fontSize = "12pt";
我想两者兼顾,这意味着CSS类从fontSize更改为
NoStyle;我不知道你给我看的第二个选项。
谢谢
I would like to do both, meaning CSS class changing from fontSize to
NoStyle; and I did not know about the second option you showed me.
Thanks
这篇关于CSS和JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!