[英]javascript onclick=“location.replace('url')” not working
i'm writing some inline javascript. 我正在写一些内联javascript。 it's not working and i'm not sure why.
它不起作用,我不知道为什么。
at the top of the index page 在索引页面的顶部
<meta http-equiv="Content-Script-Type" content="text/javascript" />
later on i have: 后来我有:
<select name='id'>
<option value=-1>New Entry</option>
<option value='1' onclick="location.replace('index.php?page=update&id=1')">2010-06-12 16:38:08</option>
<option value='2' onclick="location.replace('index.php?page=update&id=2')">2010-06-12 18:20:49</option>
<option value='3' onclick="location.replace('index.php?page=update&id=3')">2010-06-13 11:39:09</option>
</select>
what i want is for the page to be replaced when one of the option items is selected but the code is not causing a page refresh and i'm not sure why. 我想要的是当选择其中一个选项但是代码没有导致页面刷新而我不确定原因时页面被替换。 is something wrong with the javascript?
javascript有问题吗?
Use the onchange
event of the select
element: 使用
select
元素的onchange
事件:
<select name="id" onchange="window.location.replace('index.php?page=update&id='+this.options[this.selectedIndex].value);">
<option value="-1">New Entry</option>
<option value="1">2010-06-12 16:38:08</option>
<option value="2">2010-06-12 18:20:49</option>
<option value="3">2010-06-13 11:39:09</option>
</select>
Note: The location.replace
method is used when you want to navigate to the page and also replace the current page in the browsing history. 注意:当您要导航到页面并且还替换浏览历史记录中的当前页面时,将使用
location.replace
方法。 If you just want to navigate to the page normally, you assign the URL to the window.location.href
property instead. 如果您只是想要正常导航到该页面,请将URL分配给
window.location.href
属性。
我发现window.location.href
在较新的浏览器(FF4,Chrome 10等)中根本不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.