0

我正在使用一个 Web 程序,该程序将组合框发布到以下代码中的默认“全部”值:

<select size="1" name="W45_Sl" id="W45_Sl" style="cursor: pointer;">
<option class="selected" value="u;" selected="1">(All)</option>
<option class=" nAll" value="h6512;73D71A62420B4A8431F3DF84098216AA">2/22/2013</option>
<option class=" nAll" value="h6511;73D71A62420B4A8431F3DF84098216AA">2/21/2013</option>
<option class=" nAll" value="h6510;73D71A62420B4A8431F3DF84098216AA">2/20/2013</option>
</select>

当您更改网页中组合框的值时,它会更改如下代码以操作目标对象:

<select size="1" name="W45_Sl" id="W45_Sl" style="cursor: pointer;">
<option class="" value="u;" selected="1">(All)</option>
<option class=" nAll" value="h6512;73D71A62420B4A8431F3DF84098216AA">2/22/2013</option>
<option class=" nAll selected" value="h6511;73D71A62420B4A8431F3DF84098216AA">2/21/2013</option>
<option class=" nAll" value="h6510;73D71A62420B4A8431F3DF84098216AA">2/20/2013</option></select>

我想通过 jquery 做的是将加载时的组合框更改为默认值,以便它更改目标对象,我编写了以下 jquery 来更改组合框:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>$(document).ready(function() { $("#W45_Sl").removeClass("selected");});</script>
<script>$(document).ready(function() { $("#W45_Sl").val("h6511;73D71A62420B4A8431F3DF84098216AA");});</script>
<script>$(document).ready(function() { $("#W45_Sl").addClass(" nAll selected");});</script>

我的问题是组合框将反映“h6511;73D71A62420B4A8431F3DF84098216AA”“2/21/2013”​​的更新值,但类代码和目标对象不会改变。

我究竟做错了什么?

4

1 回答 1

0

尝试

$(function()
{
    $("#W45_Sl").removeClass("selected").attr("value","h6511;73D71A62420B4A8431F3DF84098216AA").addClass("nAll selected");      
});
于 2013-02-23T05:22:05.587 回答