检索表单的"名"属性在Javascript,而输入名称为&QUOT存在;名" [英] Retrieve form's "name" attribute in Javascript whereas an input exists with name "name"

查看:178
本文介绍了检索表单的"名"属性在Javascript,而输入名称为&QUOT存在;名"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的事情HTML结构:

I have something like this HTML structure :

   <form name="myvalue" id="hello">
      <input type="text" name="name" />
    </form>

我想找回在Javascript表单的name属性,具有跨浏览器的解决方案。

I'd like to retrieve the form's name attribute in Javascript, with a cross browser solution.

显然,

document.getElementById("hello").name 

将无法工作,因为它会返回相应的输入对象。

won't work because it will return the corresponding input object.

在Chrome浏览器,下面code的作品,但我没有成功找到Internet Explorer 8的

Under chrome, following code works, but I didn't succeeded to find the equivalent for Internet Explorer 8

document.getElementById("hello").getAttribute("name")

在此先感谢!

弗雷德里克

推荐答案

我觉得这oughtta工作

I think this oughtta work

document.getElementById("hello").attributes["name"].value;

在IE8测试好了,这就是我的全部。你可能必须做一些浏览器检查,并挑选你的方法需要。

tests ok in IE8, which is all I have. you might have to do some browser checking and pick your approach as needed.

编辑:其实,你的榜样,在IE8中正常工作对我来说太。但不是IE7。

edits: actually, your example works fine for me in IE8 too. but not ie7.

这篇关于检索表单的&QUOT;名&QUOT;属性在Javascript,而输入名称为&QUOT存在;名&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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