为什么 IE 中按钮的 value 属性指定为 = false?
我一直在寻找一种优雅的解决方案来将提交按钮转换为按钮。在 Internet Explorer 中,您不能简单地更改输入的类型。我也无法更改对象克隆上的属性,因此我想我可以通过创建一个新对象来手动复制它,然后迭代提交按钮的属性来复制它们。我在设置属性之前检查是否已指定该属性,但由于某种原因,尽管有明确的值,但 value 属性读取为 attrib.specified 为 false。这是为什么呢?
更新
我希望按钮()在我没有打开 javascript 时提交,并且我想在 javascript 开启时执行 javascript 而不是提交通过更改输入类型以防止回发并附加事件处理程序来打开。我考虑过完全替换按钮,但为了样式的目的,我希望尽可能保持一致,因此从提交类型切换到按钮,并且我想保留与提交按钮相关的所有其他内容,即样式、值等我只想做submitButton.type = 'button',但MSIE不喜欢这样做,因为一些相当模糊的原因。我讨厌和 MSIE 摔跤。
I have been looking for an elegant solution to converting a submit button to a button. In Internet Explorer you cannot simply change the type of an input. I couldn't change the attribute on a clone of the object either, so I thought I would manually duplicate it by creating a new object and then iterate through the attributes of the submit button to duplicate them. I am checking if the attribute is specified before setting it, but for some reason the value attribute reads as attrib.specified is false despite having a clear value. Why is this?
Update
I want buttons (<input type="input"...>
) to submit when I don't have javascript turned on, and I want to execute javascript instead of submitting when javascript is turned on by way of changing the input type to prevent postbacks and to attach event handlers. I have considered replacing the buttons entirely but I would like to be as consistent as possible for the sake of styling, hence switching to button from a submit type, and I want to preserve everything else associated with the submit button, i.e. style, value etc. I would like to just do submitButton.type = 'button', but MSIE does not like this for some rather obscure reason. I hate wrestling with MSIE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iirc IE 将提交
button
标记之间的文本,而不是其 value 属性。我相信解决方法是烧毁微软总部。
您可以使用隐藏字段或
type=submit
并向带有图像的按钮添加文本。你想达到什么目的?
iirc IE will submit the text between the
button
tags, rather than its value attribute.I believe a workaround is to burn down microsoft HQ.
You could use a hidden field, or a
type=submit
and add text to the button with an image.What are you trying to achieve?
我怀疑 noscript 标签是解决客户端缺少 js 的最佳方法。我宁愿找到一个解决方案,其中 js 将功能添加到现有页面。
I suspect noscript tags are the best way to get around the lack of js on the client side. I would just rather have found a solution where js added functionality to an existing page.