您可能认为我安装了jquery。这是一个图片下拉,使用苏莱曼先生的插件msDropdown(www.marghoobsuleman.com)我无法弄清楚为什么这不起作用。可能是我遗漏的语法错误......
<select name="websites2" id="websites2" style="width:318px;" tabindex="1">
<option name="one" value="Free" selected="selected" title="suleman_drpdwn/images/FREEButtonmenu.png">Free Trial</option>
<option name="two" value="Flexi" title="suleman_drpdwn/images/FlexiButtonmenu.png">Flexi Plan</option>
<option name="three" value="Grow" title="suleman_drpdwn/images/GrowButtonmenu.png">Grow Plan</option>
<option name="four" value="Excel" title="suleman_drpdwn/images/ExcelBtnMenu.png">Excel Plan</option>
<option name="five" value="Max" title="suleman_drpdwn/images/Maxbuttonmenu.png">Maxi Plan</option>
</select>
<script>
$(document).ready(function(){
$("websites2").find("option[value='"+Max+"']").attr("selected", "selected")
});
答案 0 :(得分:2)
$("websites2")
应该是
$("#websites2")
您正在做的是寻找元素<websites2></websites2>
而不是具有该ID的元素。 #
用于id。
此外,Max
并未在任何地方定义,但我假设你刚刚离开了。
答案 1 :(得分:1)
答案 2 :(得分:1)
您在选择器中缺少#
并且设置了select元素的选定选项,您只需将要选择的值传递给val()
方法,它就会选择它。
$("#websites2").val('Max');//I assume Max is the actual value and not a variable
答案 3 :(得分:0)
您需要在sites2上使用ID选择器#并使用字符串常量Max
。
$(document).ready(function(){
$('#websites2').find('option[value="Max"]').attr('selected', 'selected')
});