문제

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