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