我正在使用一个网络程序,它将组合框发布到以下代码中显示的默认“全部”值:
<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”,的更新值,但类代码和目标对象不会改变。
我做错了什么?
答案 0 :(得分:0)
尝试
$(function()
{
$("#W45_Sl").removeClass("selected").attr("value","h6511;73D71A62420B4A8431F3DF84098216AA").addClass("nAll selected");
});