模拟javascript以从下拉菜单中选择 [英] Simulate javascript to choose from dropdown
本文介绍了模拟javascript以从下拉菜单中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图模拟一个javascript来从下面的下拉列表中进行选择。我在这里尝试这个代码,但它不工作。
I am trying to simulate a javascript to choose from the dropdown list below. I am trying this code here but its not working.
$('select[name="srctype"]').val(2).trigger('change');
我在这里做错了什么?我的JavaScript搞砸了以下代码布局吗?
Am i doing something wrong here? Is my javascript messed up for this layout of code below?
我试图选择 value =single
<select name="srctype" class="formselect" onchange="typesel_change()">
<option value="any" selected="selected">any</option>
<option value="single">Single host or alias</option>
<option value="network">Network</option>
<option value="pptp">PPTP clients</option>
<option value="pppoe">PPPoE clients</option>
<option value="l2tp">L2TP clients</option>
<option value="wan">WAN subnet</option>
<option value="wanip">WAN address</option>
<option value="lan">LAN subnet</option>
<option value="lanip">LAN address</option>
</select>
推荐答案
试试:
$('select[name="srctype"]').val('single')
或
$('select[name="srctype"] option:eq(1)').prop('selected',1)
你的评论,这为你工作:
As you noted in your comment, this worked for you:
(function ($) {
$('select[name="srctype"]').val('single');
}).call(this, jQuery);
这篇关于模拟javascript以从下拉菜单中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文