[英]url action in javascript
How can write this on javascript. 如何在javascript上编写此代码。 This is on html form.
这是html形式。
<form action="@Url.Action("NewPage")" >
....
</form>
Now I have javascript function. 现在我有了javascript函数。
function validateForm() {
//var x = document.forms["form"]["fname"].value;
var x = document.getElementById('id').value;
if (x == null || x == 0 || x == "0") {
alert("stop");
return false;
}
else {
document.form.submit();
}
}
What should be in the html form action. html表单动作中应该包含什么。
EDIT: It now looks like you want to have your HTML form redirect to another page on submit. 编辑:现在看起来您想让您的HTML表单重定向到提交时的另一个页面。 To accomplish that, do this:
为此,请执行以下操作:
<form action="newurl.php" method="post">
[...]
</form>
where newurl.php
is whatever page you want to submit to. newurl.php
是您要提交的任何页面。
ORIGINAL ANSWER: 原始答案:
If you want to use javascript to change the url, which is what it looks like you want to do, use this: 如果您想使用javascript来更改url,这就是您想要的样子,请使用以下命令:
<script type="text/javascript">
location.href="http://new.url/whatever";
</script>
If you want to do it on a button-press, wrap it in a function and have the button call the function: 如果要在按下按钮时执行此操作,请将其包装在函数中,然后让按钮调用该函数:
<script type="text/javascript">
function newURL(url) {
location.href=url;
}
</script>
<input type='button' value='Google' onclick="newURL('http://google.com')" />
For redirection,Use any these 对于重定向,请使用任何这些
- alert(document.URL)
- alert(Window.location.href)
- alert(document.location.href)
So to redirect,use this function and call it appropriately: 因此要重定向,请使用此函数并适当地调用它:
function validateForm() {
//var x = document.forms["form"]["fname"].value;
var x = document.getElementById('id').value;
if (x == null || x == 0 || x == "0") {
alert("stop");
return false;
}
else {
document.form.submit();
Window.location.href="www.google.com";//redirect on form submit
}
} }
Note:If you have an action page,then give it a header. 注意:如果您有操作页面,请给它一个标题。
尝试这个
action='@Url.Action("ActionName","ControllerName")';
try this. 尝试这个。
<script type="text/javascript">
function DoRedirect() {
window.location.href = 'http://www.google.com';
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.