jQuery的.attr(“类型”,“提交”)一个按钮元素让我在IE7中一个奇怪的错误上 [英] jQuery .attr('type', 'submit') on a button element giving me a strange error in IE7

查看:209
本文介绍了jQuery的.attr(“类型”,“提交”)一个按钮元素让我在IE7中一个奇怪的错误上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解析通过 $ JSON响应。阿贾克斯()和建设从该对象的值的表格。我写剧本是漫长​​的,但这里是它在做什么:

I'm parsing a JSON response via $.ajax() and building a form from this object's values. The script I've written is long, but here's what it's doing:


  1. 动态创建:结果
    〜表单元素,结果
    〜一个fieldset元素,结果
    〜一个按钮元素,结果
    〜20个左右的文本输入和标签元素

  1. Dynamically creating:
    ~ a form element,
    ~ a fieldset element,
    ~ a button element,
    ~ 20 or so text inputs and label elements

追加投入和标签字段集

追加的按钮字段集

追加的字段集的形式

一切工作在所有浏览器IE除外一个小小的片段。我已经把范围缩小到下面这段code的。 (商务部是包含一个变量文件

Everything is working in all browsers except one small snippet in IE. I've narrowed it down to the following piece of code. (doc is a variable containing document)

fieldset.append(
    $(doc.createElement('button'))
        .addClass('ui-button')
        .attr('type', 'submit')
        .html('Re-Rate')
        .button()
);

这是第三步从上面。它创建了一个按钮元素,增加了一个类,设置了键入属性提交,给它一些文字,然后其追加到字段集。 IE浏览器失败,出现错误对象不支持此操作

This is step 3 from above. It creates a button element, adds a class, sets the type attribute to submit, gives it some text, and then appends it to the fieldset. IE fails with the error "Object doesn't support this action"

如果我注释掉 .attr()行是这样的:

If I comment out the .attr() line like this:

fieldset.append(
    $(doc.createElement('button'))
        .addClass('ui-button')
        //.attr('type', 'submit')
        .html('Re-Rate')
        .button()
);

一切正常。

如果你想知道,在 .button()方法是jQuery用户界面

If you're wondering, the .button() method is jQuery UI

推荐答案

ŧ允许您更改键入<输入> <按钮> 元素。

jQuery doesn't allow you to change the type of an <input> or <button> element.

这样做的原因是一致性,并且IE浏览器不允许你改变键入一旦它被插入到DOM。

The reason for this is consistency, and IE doesn't allow you to change the type once it's been inserted into the DOM.

这篇关于jQuery的.attr(“类型”,“提交”)一个按钮元素让我在IE7中一个奇怪的错误上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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