乘以div函数后的javascript无效

时间:2014-01-10 18:13:07

标签: javascript jquery html css

首先我使用javascript将div相乘,之后函数无法正常工作

function setDoorCount(count) {
    $('.doors').html('');
    for (var i = 0; i < count; i++) {
        var content = "<div class='door' data-door='" + i + "'><img id='door-id-" + i + "' src='' /></div>";
        $('.doors').append(content);
    }
}

之后尝试打开对话框而不是按原样运行

var selectedDoorId = 0; 
var openDialog = function() {
    selectedDoorId = $(this).attr('data-door');
    $('.dialog-button').click( function() {
        var color = $(this).attr('id');
        document.getElementById('door-id-' + selectedDoorId).src = 'http://www.#.asd' + color + '.png';
        $('#door-panel-color').dialog('close');
    });
    $('#door-panel-color').dialog('open');
}
$(function() {
    $( "#door-panel-color").dialog({
        autoOpen: false,
        minHeight: 'auto',
        width: 650,
        modal: true,
        open: function(){
            $('.ui-widget-overlay').bind('click',function(){
                $('#door-panel-color').dialog('close');
            })
        }
    })
    $('.door').click(openDialog);
});

HTML:

<div class="doors">
    <div class="door" data-door="0">
        <img class="door-color" id="door-id-0" src="http://liukuovitukku.fi/images/door-colors/pahkina.png" />
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

您需要使用我的代码替换您的两个函数,如下所示:

  function checkDoorCount(count) {
            if (parseInt(count.value) != 0) { //I made change here
                if (count.value != 0) {
                    setDoorCount(count.value);
                }
            } else {
                document.getElementById('door-count').innerHTML = '<font color="#F00">cant be letter</font>';
            }
        }
        function setDoorCount(count) {
            alert(count)
            $('.doors').html('');
            for (var i = 0; i < count; i++) {
                var content = "<div class='door' data-door='" + i + "'><img id='door-id-" + i + "' src='#'/></div>";
                $('.doors').append(content);
            }
            $('.door').click(openDialog); //added this statement
        }