为什么 IE 中按钮的 value 属性指定为 = false?

发布于 2024-09-14 13:05:18 字数 503 浏览 5 评论 0原文

我一直在寻找一种优雅的解决方案来将提交按钮转换为按钮。在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把回忆走一遍 2024-09-21 13:05:18

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?

稳稳的幸福 2024-09-21 13:05:18

我怀疑 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文