[英]Javascript functions not working when called
我在php文件中定義了2個javascript函數
<script type="javascript">
function inviaRichiesta(){
//some data elaborations
location.href = '../index.php'; //page redirect
}
function caricaDati(){
var ele = document.getElementById("int").options[document.getElementById("int").selectedIndex].text;
document.getElementById("tip").value = <?php echo $_SESSION['caricato']['tipologia']; ?>
}
</script>
但是當我更改選擇菜單中的值時它們似乎都不起作用
<select name="intervento" onchange="inviaRichiesta()" id="int">
我需要的是在選擇菜單中做出選擇后將瀏覽器重定向到頁面。 有什么線索嗎?
控制台輸出:
> [12:09:07.771] ReferenceError: inviaRichiesta is not defined @
> http://localhost/tirocinio/view/inserimento_dati_intervento.php:1
解:
要重定向到其他頁面,您不應使用location.href ,而應使用“ window.location”。 只需更換並嘗試。
您也可以嘗試
onchange =“ window.location ='.. / index.php'”
location.href -href屬性返回當前頁面的整個URL。
window.location -window.location對象可用於獲取當前頁面地址(URL)並將瀏覽器重定向到新頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.