Joe*_*les 3 html anchor jquery html-lists
我想澄清一下,我不是在寻找一种在下拉菜单中的选项中创建超链接的方法.我正在寻找一种方法来从外部页面下拉菜单中的其中一个选项.
以下面的场景为例,有A页和B页,有一个带X选项的下拉菜单.
页面A提供了指向页面B的链接,但是一旦您单击并登陆页面B,就会预先选择一个选项.
它基本上是一个锚链接,但我希望它用作外部链接.
页面A:它提供了一个指向页面B的链接,其中预先选择了"选项二"
第B页:
Run Code Online (Sandbox Code Playgroud)<select> <option id="one">Option one</option> <option id="two">Option two</option> <option id="three">Option three</option> </select>
我相信这可能是用jQuery完成的,所以我被告知.
更新:我错误地使用了<ul></ul>,<li></li>当我的意思是<select></select>,<option></option>
无需服务器工作
Page1.html
<html>
<body>
<a href="Page2.html?select=one">Select One</a>
<a href="Page2.html?select=two">Select Two</a>
<a href="Page2.html?select=three">Select Three</a>
</html>
</body>
Run Code Online (Sandbox Code Playgroud)
Page2.html
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function() {
var select = GetUrlParameter("select");
$("#" + select).attr("selected", "");
});
function GetUrlParameter(name) {
var value;
$.each(window.location.search.slice(1).split("&"), function (i, kvp) {
var values = kvp.split("=");
if (name === values[0]) {
value = values[1] ? values[1] : values[0];
return false;
}
});
return value;
}
</script>
</head>
<body>
<select id="select">
<option id="one">One</option>
<option id="two">Two</option>
<option id="three">Three</option>
</select>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)