为什么我的第一个选择器不起作用?

Why doesn't my first selector work?

我有一个 Jquery select 或我无法弄清楚的问题。

给定文档中的一个select框

<select id="N7_e7a18384-dfd4-4d6e-aaf2-7e221fde1fb3__WeightTypeID" 
name="N7[e7a18384-dfd4-4d6e-aaf2-7e221fde1fb3].WeightTypeID" disabled="">
<option selected="selected" value="1">Actual</option>
<option value="2">Estimated</option>
<option value="3">Gross</option>
</select>

当我尝试使用 select 或

 $("select[id^='WeightTypeID']").prop("disabled", false);

它似乎没有 select 并禁用下拉列表。

然而,

 $("form").find(":input").prop("disabled", false);

工作正常。有人可以解释为什么第一个 selector 不选择下拉列表吗?我想明白,所以我不会再浪费时间了。我真的很纳闷。

因为 name^=valueattribute begins with 选择器。对于 "contains",您将使用 *=。对于 "ends with," $=.