JQuery每个都不工作但按元素工作

时间:2016-10-11 13:55:51

标签: javascript jquery

我有以下代码,其中第一行正在运行,但每个部分都没有。没有语法错误,所以我不知道什么是无法正常工作。

application/json

2 个答案:

答案 0 :(得分:1)

因为这样你在jQuery对象上设置selectedIndex

$(this).selectedIndex = 2;

需要

 $(this).prop("selectedIndex", 2);

this.selectedIndex = 2;

答案 1 :(得分:1)

jQuery对象没有选择索引,请尝试:

$("select[id*='outcome']").each(function() {
        $(this).prop('selectedIndex', 2);
});