【发布时间】:2015-02-25 20:47:22
【问题描述】:
我有一个选择下拉菜单,一旦用户指定了我希望它在 2 个新标签中为 2 个 URL 链接的品牌。我该怎么做,最好为提交做onclick事件,然后通过选择运行一个带有“if and else”的函数..任何建议?这是我当前的代码。
<fieldset>
<legend><span class="number">1</span>Select a Brand</legend>
<label for="Brand">Brand:</label>
<select id="brandSelect" name="brand_select">
<optgroup label="Grills">
<option value="http://site1.com", "http://site1A.com">DCS</option>
<option value="http://site2.com", "http://site2A.com">Alfresco</option>
<option value="http://site3.com", "http://site3A.com">Viking</option>
<option value="http://site4.com", "http://site4A.com">Fire Magic</option>
<option value="http://site5.com", "http://site5A.com">Lynx</option>
<option value="http://site6.com", "http://site6A.com">Coyote</option>
</optgroup>
</select>
</fieldset>
<button type="submit">Sign Up</button>
<script type="text/javascript">
var urlmenu = document.getElementById( 'brandSelect' );
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value );
};
</script>
【问题讨论】:
-
如何将两个不同的 URL 作为一个选项放在选择列表中?例如它将是两个空格分隔的 URL 作为选项的值,还是什么?修改上面的问题代码/标记,使其包含您正在尝试做的示例。
-
好的,我在原帖中完善了我的问题。
-
所以
value="http://site6.com", "http://site6A.com"是非法的——必须将诸如值之类的属性设置为单引号字符串。这将是合法的:value="http://site6.com, http://site6A.com"或只是带有空格value="http://site6.com http://site6A.com"
标签: javascript jquery node.js forms