如何使用“action”将html页面重定向到另一个页面 [英] How to redirect html page to another page with "action"

查看:102
本文介绍了如何使用“action”将html页面重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我创建了一个小网页,我从不同的下拉框(选择框)中选择三个值。这三个值在我从这三个值构建html网页地址/名称的地方得到了连接。



我在函数中连接这三个值后,我想以action方式调用此函数,该方法将其重定向到连接的html pageI。



我的问题是,我无法获得从函数连接到重定向到specefic页面的值。我在浏览器的地址栏中获得的唯一值是函数名称(javascript:buildstring();)



请参阅下面的代码:



 <  !DOCTYPE     html  >  
< html >
< body >
< script < span class =code-attribute> type =' text / javascript' >

function buildstring()
{
var button = doc ument.getElementById('提交查询');
var method = document.getElementById('method')。options;
var accumulation = document.getElementById('accumulation');
var radar = document.getElementById('radar');

var str = String(method.value)+_
+ String(accumulation.value)+
_+ String(radar.value)+。 HTML;

return str}

< / script >

< 表格 action < span class =code-keyword> = javascript:buildstring(); target = _ blank >

< select id = method >
< 选项 已选择 > 选择方法< / option 已选择 >
< 选项 value = 点200km > 点200km < / option >
< 选项 < span class =code-attribute> value = 点70km > 点70km < / option >
< select / >

< br / >

< 选择 id = accum >
< 选项 已选择 > 选择累积< / option 已选择 >
< 选项 value = 24小时 > 24小时< / option >
< 选项 = 10天 > 10天< / option >
< 选项 value = 30天 > 30天< / option >
< select / >

< br / >
< 选择 id = 雷达 >
< 选项 已选择 > 选择Radar < / option 已选择 >
< 选项 value = Test1 > Test1; / option>
< select / >
< br / >
< 按钮 id = 提交查询 > 提交查询< / button >
< / form >
< /正文 >
< / html >





什么可以我更改了< form action =javascript:buildstring();目标= _空白 >部分,以便函数中返回的字符串值可以显示在浏览器的地址栏中,以重定向到特定的网页名称?



谢谢

解决方案

如果你坚持,试试这个:

 function buildstring()
{
var button = document.getElementById('Submit Query');
var method = document.getElementById('method'); //删除选项
var accumulation = document.getElementById('accumulation');
var radar = document.getElementById('radar');

var str = String(method.value)+_
+ String(accumulation.value)+
_+ String(radar.value)+。 HTML;

location.assign(str); //重定向到concaternated url
}

< / script >

< 表格 action = javascript:buildstring(); >


<! - 您的其他代码 - >


Hi
I've created a small web page, where i select three values from different drop down boxes(selection boxes). These three values gets concatinated where i build a html webpage address/name from these three values.

After I concatenated these three values in the function, I want to call this function in the form "action" method which will redirect it to the html pageI concatenated.

My problem is, that I can't get the value that I concatenated from the function to redirect to the specefic page. The only value that i get in the address bar of the browser is the function name (javascript:buildstring();)

See my code as below:

<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>

function buildstring()
{
var button = document.getElementById('Submit Query');
var method = document.getElementById('method').options;
var accumulation = document.getElementById('accumulation');
var radar = document.getElementById('radar');

var str = String(method.value) + "_"
          + String(accumulation.value) +
        "_"+ String(radar.value) + ".html";

return str }

</script>

<form action ="javascript:buildstring();" target="_blank">

<select id = "method">
<option selected>Select Method</option selected>
   <option value="Point 200km">Point 200km</option>
   <option value="Point 70km">Point 70km</option>
<select/>

<br />

<select id = "accumulation">
<option selected>Select Accumulation</option selected>
   <option value="24 Hour">24 Hour</option>
   <option value="10 Day">10 day</option>
   <option value="30 Day">30 Day</option>
<select/>

<br />
<select id = "radar">
<option selected>Select Radar</option selected>
<option value="Test1">Test1;/option>
<select/>
<br/>
<button id="Submit Query">Submit Query</button>
</form>
</body>
</html>



What can I change in the <form action ="javascript:buildstring();" target="_blank"> section so that the returned string value in the function can be displayed in the address bar of the browser to redirect to the specific web page name?

Thanks

解决方案

If you insist, try this:

function buildstring()
{
var button = document.getElementById('Submit Query');
var method = document.getElementById('method');  // remove options
var accumulation = document.getElementById('accumulation');
var radar = document.getElementById('radar');

var str = String(method.value) + "_"
          + String(accumulation.value) +
        "_"+ String(radar.value) + ".html";

location.assign(str);  // redirect to the concaternated url
}

</script>

<form action="javascript: buildstring();">

 
<!-- your other code -->


这篇关于如何使用“action”将html页面重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆