Javascript 仅使用链接参数进行选择
我试图得到一个下拉链接,但我不想使用链接文件名的url只是参数 代码如下:Javascript 仅使用链接参数进行选择,javascript,Javascript,我试图得到一个下拉链接,但我不想使用链接文件名的url只是参数 代码如下: <script type="text/javascript"> function goToNewPage(){ var url = document.getElementById('list').value; if(url != 'none') { window.location = url; } } </scrip
<script type="text/javascript">
function goToNewPage(){
var url = document.getElementById('list').value;
if(url != 'none') {
window.location = url;
}
}
</script>
<select name="list" id="list" accesskey="target">
<option value='none' selected>Choose an item</option>
<option value="?one">item1</option>
<option value="?two">item2</option>
<select>
<input type=button value="Go" onclick="goToNewPage()" />
If I use: <option value="index.html?one">item1</option> it will work but:
函数goToNewPage(){
var url=document.getElementById('list')。值;
如果(url!=“无”){
window.location=url;
}
}
选择一个项目
项目1
项目2
如果我使用:item1,它将工作,但:
我如何让它与它一起工作…像这样:
<option value="?one">item1</option> ?
item1?
您可以使用:
如果链接文件名为“index.html”,则应使用:
<script type="text/javascript">
function goToNewPage(){
var url = document.getElementById('list').value;
if(url != 'none') {
window.location = "index.html" + url;
}
}
</script>
函数goToNewPage(){
var url=document.getElementById('list')。值;
如果(url!=“无”){
window.location=“index.html”+url;
}
}
index.html
已修复?您可以执行window.location=“index.html”+url代码>没有它就不能工作吗?例如,如果您在链接上执行此操作:…它将起作用。不能对select执行同样的操作吗?应该这样做。.search
在url的末尾添加了?url=1
部分。这是您使用的全部代码吗?你的HTML呢?你是在用Iframe还是什么?
<script type="text/javascript">
function goToNewPage(){
var url = document.getElementById('list').value;
if(url != 'none') {
window.location = "index.html" + url;
}
}
</script>