我的问题:此代码适用于 firefox chrome 和 safari 但不适用于 IE 8。我有 .change
但我发现它在 ie 中不起作用所以我做了 .click
并在所有浏览器中再次尝试,一切正常,尝试 ie 仍然无法正常工作。 anythingSlider 是我正在使用的一个 jquery 库,我确信这不是问题所在(反向工作就像选择下拉菜单中的项目并移动到该幻灯片在任何地方都有效,包括 ie。谢谢。
我的代码:
$(document).ready(function() {
$('#skillslist').click(function()
{var str = $(this).attr('value');
var pattern = /[0-9]+/g;
var matches = str.match(pattern);
var myInteger = parseInt(matches);
$('#slider').anythingSlider(myInteger);
});
});
</script>
<select name='myList' id='skillslist'>
<option>Subscription Days Remaining: <? echo $days ?></option>
<option id='skill1'>Skill 1: Hand Washing</option>
<option id='skill2'>Skill 2: Abdominal Thrust on Conscious Resident</option>
<option id='skill3'>Skill 3: Ambulation using a Gait Belt</option>
</select>
最佳答案
$('#skillslist').change(function() {
var str = $(this).val();
// ...
});
我总是尽量避免使用 $(this).attr('value')
或 this.value
,因为应该使用 this 查询选择框值.options[this.selectedIndex]
...这就是 .val()
为您所做的。
在您说“它不起作用”之前先描述什么不起作用,并确保通过 alert()
ing myInteger
值消除其他因素。
关于javascript - .change() 在 ie 中不起作用,当更改为 .click() 时同样的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10868794/