为所有具有相同名称的输入框更改css bu javascript [英] changing css bu javascript for all input boxes with the same name
问题描述
大家好,
我知道我做了一些非常愚蠢的事情,但我不能这样做
工作......
我有一个带有一堆输入的表单,名为ship_owner [] - 为什么
[]?因为我通过php提交了这个页面并且[]将数据
放入帖子中的数组....任何时候。
我有一个链接< a href =" javascript :change_class()" >阻止模式< / a> to
调用我头脑中的以下函数。
< script>
函数change_class(var_type)
{
for(i = 0; i< document.getElementsByName(''ship_owner []'')。length; i ++)
{
document.getElementsByName(''ship_owner []'')[i] .style.className =" input_to_text";
}
}
< / script>
我脑子里还有以下样式表。
< style> ;
<! -
input_to_text {
border:1px solid#000;
背景:# 987;
填充:1px;
字体系列:Veranda;
字体大小:10px;
颜色:#fff;
font-weight:bold;
}
< / style>
我点击链接我的输入框根本没有变化......
帮助:-)
很多很多谢谢
艾米
am ******* @ gmail.com aécrit:
< script>
function change_class(var_type)
{
// if您的表单是您文件中的第一个说什么这些提醒?
alert(''dom =''+ document.getElementsByName(''ship_owner []'')。length);
alert(''js =''+ document.forms [0] .elements [''ship_owner []'']。length);
for(i = 0; I< document.getElementsByName( ship_owner [])的长度。; i ++)
{
document.getElementsByName(''ship_owner []'')[i] .style.className =" input_to_text";
}
}
< / script>
我脑子里还有以下样式表。
< style>
<! -
input_to_text {
边框:1px solid#000;
背景:#987;
填充:1px;
字体系列:Veranda;
font-family:Veranda;
font-size:10px;
颜色:#fff;
font-weight:bold ;
}
/ *别忘了 - >最后* /
- >
< / style>
-
Stephane Moriaux et son [moins] vieux Mac
am ******* @ gmail.com 写道:大家好,
我知道我''我做了一件非常愚蠢的事情,但是我不能把它当作工作......
我有一个带有一堆输入的表格,名为ship_owner [] - 为什么
[]?因为我正在通过php提交这个页面而且[]将数据
放入帖子中的数组....任何时候。
我有一个链接< a href = "的JavaScript的 的:change_class()" >阻止模式< / a>
调用以下函数在我的头部。
< script>
函数change_class(var_type)
for( i = 0; i< document.getElementsByName(''ship_owner []'')。length; i ++)
document.getElementsByName(''ship_owner []'')[i ] .style.className =" input_to_text";
应该是
var inputs = document.getElementsByName(" ship_owner [] ");
for(var i = 0; i< inputs.length; i ++)
inputs [i] .className =" input_to_text";
1.className是元素的属性,而不是它的样式属性。
2.为了提高效率,避免多次调用函数。 < span
class =" GreybeardDeveloper">(现在不要让程序员想到这样的事情吗?)< / span>
}
< / script>
我脑子里还有以下样式表。
< style>
< ; -
input_to_text {
border:1px solid#000;
背景:#987;
填充:1px;
字体系列:Veranda;
font-size:10px;
颜色:#fff;
font-weight:bold;
尝试将其放入文档然后!
;-)
......
Nige >
am*******@gmail.com :
< snip>我有一个链接< a href =" javascript :change_class()" >阻止模式< / a>
< snip>
不要将javascript伪协议HREF用作Windows IE(和a
其他一些浏览器)将其激活作为代表导航,
并将当前页面置于等待状态,等待其
替换。在等待状态下,各种以前功能齐全的浏览器功能将停止工作。基本上,一旦用户点击这样的链接
,关于浏览器随后可以做什么的所有投注都是关闭的。使用
默认动作取消onclick处理程序来触发函数
。
Richard。
Hi all,
I know I''m doign something really daft, but I can''t get this to
work...
I have a form with a bunch of inputs called ship_owner[] - why the
[]? Because I''m submitting this page though php and the [] put the data
into an array in the post.... anywhat.
I have a link <a href="javascript:change_class()" >Block mode</a> to
call the following function that''s in my head section.
<script>
function change_class(var_type)
{
for (i=0; i<document.getElementsByName(''ship_owner[]'').length; i++)
{
document.getElementsByName(''ship_owner[]'')[i].style.className="input_to_text";
}
}
</script>
I have the following style sheet also in my head.
<style>
<!--
input_to_text {
border: 1px solid #000;
background: #987;
padding: 1px;
Font-family: Veranda;
font-size: 10px;
color: #fff;
font-weight: bold;
}
</style>
When I click the link my input boxes aren''t changing at all......
help :-)
Many many thanks
Amy
am*******@gmail.com a écrit :
<script>
function change_class(var_type)
{
// if your form is the 1st in your file what say these alerts ?
alert(''dom = ''+document.getElementsByName(''ship_owner[]'').length);
alert(''js = ''+document.forms[0].elements[''ship_owner[]''].length);
for (i=0; i<document.getElementsByName(''ship_owner[]'').length; i++)
{
document.getElementsByName(''ship_owner[]'')[i].style.className="input_to_text";
}
}
</script>
I have the following style sheet also in my head.
<style>
<!--
input_to_text {
border: 1px solid #000;
background: #987;
padding: 1px;
Font-family: Veranda;
font-family: Veranda;
font-size: 10px;
color: #fff;
font-weight: bold;
}
/* don''t forget --> in end */
-->
</style>
--
Stephane Moriaux et son [moins] vieux Mac
am*******@gmail.com wrote:Hi all,
I know I''m doign something really daft, but I can''t get this to
work...
I have a form with a bunch of inputs called ship_owner[] - why the
[]? Because I''m submitting this page though php and the [] put the data
into an array in the post.... anywhat.
I have a link <a href="javascript:change_class()" >Block mode</a> to
call the following function that''s in my head section.
<script>
function change_class(var_type)
{
for (i=0; i<document.getElementsByName(''ship_owner[]'').length; i++)
{
document.getElementsByName(''ship_owner[]'')[i].style.className="input_to_text";
That should be
var inputs = document.getElementsByName("ship_owner[]");
for (var i = 0; i < inputs.length; i++)
inputs[i].className = "input_to_text";
1. "className" is a property of the Element, not it''s style property.
2. Avoid multiple calls to functions just for efficiency. <span
class="GreybeardDeveloper">(Don''t programmers think about things like
this nowadays?)</span>
}
</script>
I have the following style sheet also in my head.
<style>
<!--
input_to_text {
border: 1px solid #000;
background: #987;
padding: 1px;
Font-family: Veranda;
font-size: 10px;
color: #fff;
font-weight: bold;
Try putting it into your document then!
;-)
......
Nige
am*******@gmail.com wrote:
<snip>I have a link <a href="javascript:change_class()" >Block mode</a>
<snip>
Do not ever use javascript pseudo-protocol HREFs as Windows IE (and a
few other browsers) takes their activation as representing navigation,
and that puts the current page into a ''waiting'' state, pending its
replacement. In that ''waiting'' state various previously functional
browser features stop working. Basically, once a user clicks such a link
all bets are off as to what the browser may subsequently do. Use a
default-action cancelling onclick handler to trigger the function
instead.
Richard.
这篇关于为所有具有相同名称的输入框更改css bu javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!