如何使用javascript更改id下公共类名定义的所有输入类型 [英] How to change all input type define by a common class name under id using javascript

查看:55
本文介绍了如何使用javascript更改id下公共类名定义的所有输入类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

the code is given below:

<div id="1">
<input type="hidden" name="name" value="dgfdf" class="chk"/>
<input type="hidden" name="email" value="gh@yahoo.com" class="chk"/>
<input type="hidden" name="phone" value="475684" class="chk"/>
<input type="hidden" name="address" value="f46d/a" class="chk"/>
<input type="hidden" name="id" value="2" class="id"/>
</div>







这里我想更改'隐藏到文本类型'所有输入fild哪个类名是




here i want to change 'type hidden to text' all input fild which class name is

chk

在div id中1.我可以用javascript做这个。

如需了解更多,我可以在下面给出更改后的代码:



inside div id 1.how can i do this using javascript.
For more understand i give the changed code below:

<div id="1">
<input type="text" name="name" value="dgfdf" class="chk"/>
<input type="text" name="email" value="gh@yahoo.com" class="chk"/>
<input type="text" name="phone" value="475684" class="chk"/>
<input type="text" name="address" value="f46d/a" class="chk"/>
<input type="hidden" name="id" value="2" class="id"/>
</div>





我尝试过:



i无法理解我应该怎么做rt。



What I have tried:

i cannot understand how should i start.

推荐答案

Hello

如果您设计的网站只能在Mozilla,Safari或其他非Internet上运行在Explorer浏览器中,以下代码足以修改输入元素的类型:



Hello
If you are designing a site that is intended only to run on Mozilla, Safari, or another non-Internet Explorer browser, the following code is sufficient to modify an input element's type:

<script>
  document.getElementsByClassName('chk').type = 'text';
</script>





希望它有效



hope it works


试试这个

try this
var div = document.getElementById('1'); 
            var chks = div.getElementsByClassName('chk'); 
            for (var i = 0; i < chks.length; i++) { 
                chks[i].type = 'text';
            }


这篇关于如何使用javascript更改id下公共类名定义的所有输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆