سؤال

I have a form that runs a calculation based on what's entered in another field. This works fine in everything except IE7 which I have to support for this project.

I've run some tests and everything appears to trigger up until the point that the jquery tried to change the state of select field.

I'm using the following line that IE7 is dying on:

$('#selectField').val("someval").change();

Any help is appreciated.

هل كانت مفيدة؟

المحلول 3

The solution here as per this thread:

Try using .click instead of .change

نصائح أخرى

Depending on the jQuery version you're using, try this way:

$('#selectField').prop("value", "someval");

If it still doesn't work, try this:

$('#selectField').attr("value", "someval");

The .val() should work just fine, but for reasons unknown (or just IE7 knows) it just doesn't work.

It's because select field has options that have selected property.

This should work:

var newOptionValue = 'option5';
$('select[id="selectField"]').find('option[value="' + newOptionValue + '"]').attr("selected", true);
$('select[id="selectField"]').trigger('change');
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top