开发者

jQuery populate div from select option - IE7 issues

I am trying to populate a div with the value of an <option> in a <select> list.

My jQuery is:

$('select#address_select_previous').click(function () {
    var previousAddress = $('select#address_select_previous option:selected').text();
    previousAddress = previousAddress.replace(/, /g, ', <br />'); 
    $('#previous_address_populated p').html(previousAddress);   
});       

I originally had .change(function()) but I found out here, that IE 7 doesn't like that.

The problem is that the var previousAddress has no value (i.e. if I console log, or alert that value, it is null in IE7, but fine in other browsers), so it won't populate the div, as ther开发者_Python百科e is nothing to populate it with.


-- EDIT --

see working jsFiddle demo

I also made some slight optimizations:

var $select = $('select#address_select_previous'),
    $populated = $('#previous_address_populated p');

$select.change(function() {
    $populated.html($select.val().replace(/, /g, ', <br />'));
}).change();


Perhaps

$('select#address_select_previous').val();

.change() should be working though...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜