日期:2014-05-16  浏览次数:20379 次

来帮忙看下这个问题,本人不是专业技术人员,前来求高人指教!
JScript code

$(document).ready(function(){
    var I = 1;
    //fblog-add1                         
    $("#fblog-add1").click(function() {
        if ($(".selectl-inner-sizel dl").size() < 5) {                           
            I = I + 1;
            Size = "Size" + I + "_Id";
            alert(Size);
            $('.selectl-inner-sizel').append(
                '<dl class="frame-sel-filed pdt10">' +
                '<dd class="frame-sel-dd-01">文胸尺码</dd>' +
                '<dd class="select-box"><span>请选择...</span>' +
                '<ul class="select-ul">' +
                '<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">32A</li>' +'<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">32B</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">32C</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">32D</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">32DD</li>' +'<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">34A</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">34B</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">34C</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">34D</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">34DD</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">36A</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">36B</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">36C</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">36D</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">36DD</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">38B</li>' +'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">38C</li>' +
                '<li onclick="javascript:document.getElementById(Size).value = this.innerHTML;">38D</li>'+'<li class="bg-fff" onclick="javascript:document.getElementById(Size).value = this.innerHTML;">38DD</li>' +
                '</ul>' + '</dd>'+'</dl>');};
    });
    $("#fblog-reduce1").click(function() {
        if ($(".selectl-inner-sizel dl").size() > 1) {
            I = I - 1;
              $(".selectl-inner-sizel dl:last-child").remove();
            };
    });
});



效果大概为点一次 添加一批内容,而次添加的内容都要计数,比如最开始I=1,那么第一次点击添加内容的时候,getElementById(Size)中,SIZE的值应该是size2_id,以此类推,第二次点击,getElementById(Size)中SIZE的值应该是size3_id,我想利用这种办法跟几个HIDDEN的文本框对应,但是实际情况是点了几次添加后,前面已经生成的所有getElementById(Size)中,SIZE的内容都变成了最后一次的SIZE的值,如何解决这个问题?