我有一個HTML頁面,我有一個下拉菜單和一個按鈕。下拉元素選擇和JS調用不起作用
選擇一個元素後,按下按鈕和我通話功能採取行動,按照下面的代碼:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Custom dropdown</title>
<link rel="stylesheet" href="cssdropdown/style.css">
</head>
<body>
<h3>Restart any service from here</h3>
<!--form method="post" action="example_new.php"-->
<span class="custom-dropdown">
<select name="restart-component" id="restart-component">
<option value=0>Data 1</option>
<option value=1>Data 2</option>
</select>
</span>
<button id="submit" name="submit" style="background-color:#1abc9c padding-left: 2cm;" onclick='goToRestart();'>Restart</button>
<p>Legend</p>
<br/>
<script type="text/javascript">
function goToRestart() {
alert ("into js");
var url;
var location = document.getElementById("restart-component").selectedIndex;
if (location == 1) {
url = 'http://www.page.com/west';
}
else if (location == 2) {
url = 'http://www.page.com/land';
}
#window.location.href=url;
alert(url)
}
</script>
<script src='http://ajax.googleapis.com/ajax/libs/prototype/1.7.1/prototype.js'></script>
<script src="jsdropdown/index.js"></script>
</body>
</html>
但我的JavaScript函數不會被調用。我錯過了什麼嗎?請幫忙。
任何錯誤? – Lal
如果您可以在[小提琴](https://jsfiddle.net/) – Lal
'type ='button''中重現問題,這將會非常有幫助嗎? '#window.location.href' =>'window.location.href' – Rayon