动态创建IE7单选按钮问题 [英] IE7 radio button issue when created dynamically

查看:110
本文介绍了动态创建IE7单选按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建单选按钮克隆时,我在IE7中遇到了问题。我正在动态更新名称和ID属性,但是,我仍然有一个问题,即正在检查的单选按钮会重置已动态创建的其他任何按钮。知道如何解决这个问题吗? 以下是问题的解答

I have an issue in IE7 when I am creating clones of radio buttons. I am dynamically updating the name and ID attributes, however, I still have the issue that a radio button being checked resets any of the others which have been created dynamically. Any idea how this can fixed? Here is a fiddle of the issue

这是操纵表单字段的JS代码:

This is the JS code which manipulates the form fields:

// Dropdown select
$('#quantity').live("change", function(){

    $('.questions_clonable:not(.questions_clonable:first)').remove();


    // Get value of selection
    var num = $(this).val();

    var cloned_el = $('.questions_clonable').clone();   

    if (num > 1)
    {  
        for (var i = 1; i < num; i++)
        {
            // Assign cloned block to new var
            var new_block = cloned_el;  

             // Store previous number for replacing with current in cloned block input fields
                var prev = i-1;

                // Update input name to make it unique
                new_block.find('input').each(function() {     
                    this.name = this.name.replace(prev, i); 
                    this.id = this.id + i; 
                });

            // Bit of a workaround needed to clone properly, reiterating class name
            $('.multiple_questions_container').append('<span class="questions_clonable hidden">'+new_block.html()+'</span>');

        }   
    }
});​


推荐答案

我找到了几个可能的修复方法,但以下工作完美:

I found several possible fixes for this but the following worked perfectly:

function setElementName(elems, name) {
        if ($.browser.msie === true){
            $(elems).each(function() {
                this.mergeAttributes(document.createElement("<input name='" + name + "'/>"), false);
            });
        } else {
            $(elems).attr('name', name);
        }
    } 

这篇关于动态创建IE7单选按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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