我有一个下拉菜单的值从我的sql数据库拉出来。
选择值后,将其存储在一个变量中。
假设我选择了一个选项"ABC",并将其存储到变量中,然后我想使用该变量打开本地主机上名为ABC.html的html文件
目标通常是将用户重定向到与其选择相关的网页。
下面是我的脚本:<html>
<head>
<script>
function getOption() {
var obj = document.getElementById("choosedOP");
document.getElementById("demo").innerHTML =
obj.options[obj.selectedIndex].text;
}
</script>
<title>ComboBox Ajax, PHP y MySQL</title>
<script src="includes/js.js"></script>
</head>
<body onload="getOp1();">
<div id="op1"></div> <br />
<div id="op2"></div> <br />
<div id="op3"></div>
<input type="button" onclick="getOption()" value="Click Me!">
</form>
<p id="demo"></p>
</body>
</html>
当我点击提交按钮时,它检索选中的选项。我怎么能使它重定向到任何html选择的用户?
<html>
<head>
<script>
function getOption() {
obj = document.getElementById("choosedOP");
document.getElementById("demo").innerHTML =
obj.options[obj.selectedIndex].text;
}
function redirect(){
obj = document.getElementById("choosedOP");
var href = obj.options[obj.selectedIndex].text;
window.location=href;
}
</script>
<title>ComboBox Ajax, PHP y MySQL</title>
<script src="includes/js.js"></script>
</head>
<body>
<input type="button" id="redirect" value="redirect" onclick="redirect()">
<select id="choosedOP">
<option>http://wiki.com</option>
<option>https://www.wikipedia.org/</option>
</select>
<div id="op1"></div> <br />
<div id="op2"></div> <br />
<div id="op3"></div>
<input type="button" onclick="getOption()" value="Click Me!">
</form>
<p id="demo"></p>
</body>
</html>
function redirect(){
obj = document.getElementById("choosedoption");
var href = obj.options[obj.selectedIndex].text;
window.location.href = 'obj.php?=' + this.options[this.selectedIndex].value;">
这有什么意义吗?