Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

Updating the text of a button with javascript

I'm trying to update the button as it counts down to a link being live, but the button text is not being updated...

here's my script

var meetings_default_view_default = {

start: function () {

    window.setInterval(function () {
        
        var _div = $('.meetings_wrapper');
        var _meeting_id = [];
        var _url = _div.data('url');

        // Collect all the relevant meeting ids
        _div.children().each(function () {
            _meeting_id.push($(this).data('id'));
        });

        if (!_meeting_id.length) {
            return;
        }
        
        $.post(_url, {meeting_id: _meeting_id}, function(data) {
            
            if (data.alert) {
                alert(data.alert);
                return false
            };
            
//                if (!data.meeting_id) {
//                    alert('No data returned');
//                }
            
            for (var i in data.meeting_id) {
                var meeting_data = data.meeting_id[ i ];
                var meeting_id = meeting_data[ 'id' ];
                // locate the start button *within* the panel with the appropriate id
                var _button = _div.find('.panel[data-id=' + meeting_id + '] a.button').last();
                var _css = 'button';
                
                if (meeting_data['css_class']) {
                    _css += ' ' + meeting_data['css_class'];
                }

                _button.attr('class',_css);
                
                if (meeting_data['label']) {
                    _button.find('span').text(meeting_data['label']);
                }
                
            }
            
        });
        


    }, 60000);
}
};

$(meetings_default_view_default.start);

everything else ( css ) changes, just not the text of the button ? been staring at this for ages now !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

sorry, another silly mistake when tired. This works fine...

                if (meeting_data['label']) {
                       _button.text(meeting_data['label']);
                }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...