var sex = $("#search_form select[name='sex'] option:selected ").attr("value");
var sex = $("#search_form select[name=sex'] option[selected]").attr("value");
这样写会有问题 sex的值有时是undifined
改为
var sex = $("#search_form select[name='sex'] option:selected ").attr("value");
var val = $("#search_form select[name='sex']").children('option:selected').val();
这样就去到了
jquery option selected
最新推荐文章于 2024-05-03 13:26:42 发布
本文探讨了在JavaScript中使用选择器选择元素时遇到的问题,特别是当选择器返回的值为undefined时的解决方案。通过修改代码,确保获取到的元素值始终正确赋值,避免了潜在的错误。
219

被折叠的 条评论
为什么被折叠?



