页面重定向(Page Redirection)
我正在处理一个脚本,我希望脚本(现在)根据他们按下哪个按钮来重定向用户。 最终它将采用表单输入并将其合并到重定向中,但现在我只是试图让按钮将用户发送到适当的站点。 但是,我的重定向不起作用。
<html> <head> <title> Home </title> </head> <body> <script type="text/javascript"> <!-- var textstring; var btnWhichButton; //Gets the text from the form function getQ() { textstring = document.forms['Search'].elements[0].value; } //Does a Google Search function googleSearch() { window.location ="http://www.google.com"; } //Does a YouTube Search function youtubeSearch() { window.location = "http://youtube.com"; } //Figure out which button was pressed function whichButton() { if (btnWhichButton.value == 'Google Search' ) { googleSearch(); } else if (btnWhichButton.value == 'YouTube Search' ){ youtubeSearch(); } } //main function to run everything function main() { getQ(); whichButton(); } // --> </script> <form name="Search" > <input type="text" name="q" size="31" maxlength="255" value="" /> <input type="submit" value="Google Search" onclick="btnWhichButton=this; main();" /> <input type="submit" value="YouTube Search" onclick="btnWhichButton=this; main();" /> </form> </body> </html>
当任一按钮被点击时,页面只会重新加载?q =追加到url,它不会重定向。 任何帮助?
I'm working on a script where all I want it to do (right now) is redirect the user based on which button they press. Eventually it will take form input and incorporate that into the redirect, but right now I'm just trying to get the buttons to send the user off to the appropriate site. However, My redirects aren't working.
<html> <head> <title> Home </title> </head> <body> <script type="text/javascript"> <!-- var textstring; var btnWhichButton; //Gets the text from the form function getQ() { textstring = document.forms['Search'].elements[0].value; } //Does a Google Search function googleSearch() { window.location ="http://www.google.com"; } //Does a YouTube Search function youtubeSearch() { window.location = "http://youtube.com"; } //Figure out which button was pressed function whichButton() { if (btnWhichButton.value == 'Google Search' ) { googleSearch(); } else if (btnWhichButton.value == 'YouTube Search' ){ youtubeSearch(); } } //main function to run everything function main() { getQ(); whichButton(); } // --> </script> <form name="Search" > <input type="text" name="q" size="31" maxlength="255" value="" /> <input type="submit" value="Google Search" onclick="btnWhichButton=this; main();" /> <input type="submit" value="YouTube Search" onclick="btnWhichButton=this; main();" /> </form> </body> </html>
When either button is clicked, the page just reloads with ?q= appended to the url, it doesn't redirect. Any help?
原文:https://stackoverflow.com/questions/2361419
最满意答案
这是一个减少的repro:
let f x (y:System.IComparable) = () let g = f 1 g 3 g "test" // not okay let g' : System.IComparable -> unit = f 1 g' 3 g' "test" // okay let g'' x = f 1 x g'' 3 g'' "test" // okay
g:('a -> unit) when 'a :> System.IComparable
我的例子中的g:('a -> unit) when 'a :> System.IComparable
,编译器推断出g
(g:('a -> unit) when 'a :> System.IComparable
的泛型类型。 但是,g
是一个语法值,因此不能通用(请参阅有关值限制的问题),因此编译器需要选择特定类型。 如果您根本不使用g
,则会出现编译器错误。 如果您只使用一种具体类型,编译器将选择该类型。 如果您在多种类型下使用它,编译器将根据使用的第一种类型进行专门化,然后抛出错误。两种解决方法是使用非泛型类型进行注释或者进行eta-expand,以便
g
不是语法值。Here's a cut down repro:
let f x (y:System.IComparable) = () let g = f 1 g 3 g "test" // not okay let g' : System.IComparable -> unit = f 1 g' 3 g' "test" // okay let g'' x = f 1 x g'' 3 g'' "test" // okay
What happens is that the compiler infers a generic type for
g
(g:('a -> unit) when 'a :> System.IComparable
in the case of my example). However,g
is a syntactic value and therefor can't be generic (see questions about the value restriction), so the compiler needs to pick a specific type. If you don't useg
at all, you'll get a compiler error. If you use it at exactly one concrete type, the compiler will pick that type. If you use it at more than one type, the compiler will specialize based on the first type used and throw an error after that.Two workarounds are to either annotate with a non-generic type or to eta-expand so that
g
isn't a syntactic value.
相关问答
更多-
clang - 错误:不支持裸函数中的非ASM语句(clang - error: non-ASM statement in naked function is not supported)[2022-12-11]
我应该把它写成答案而不是评论。 问题是: 为什么Clang不支持裸函数中的非ASM语句? 这在gcc上工作正常。 答案是,这在gcc 中不能正常工作。 引用gcc docs中的naked属性: 只有基本的asm语句可以安全地包含在裸函数中。 虽然使用扩展的asm或基本的asm和C代码的混合似乎可行,但它们不能依赖于可靠地工作而不受支持。 如果用一种不那么含糊的方式来表达这一点,我就无法想出来。 请注意,虽然上面的特定链接是针对ARM的(我猜这是OP正在使用的),但我相信相同的文本适用于所有支持naked平台 ... -
在Firebase SDK的发行说明中,它提到版本11.6.0: 功能:添加了对使用通配符通用参数(例如kotlin.Map)反序列化字段类型的支持。 听起来你应该只将客户端库升级到11.6.0。 In the release notes for the Firebase SDKs, it mentions for version 11.6.0: Feature: Added support for deserializing field types with wildcard generic parame ...
-
这肯定在某些时候发生了变化。 它出现在9.25.2017,openxml在SQL Azure中运行良好。 我刚从SQL Azure DB上的https://docs.microsoft.com/en-us/sql/relational-databases/xml/examples-using-openxml运行以下示例,它生成了显示的结果: DECLARE @DocHandle int DECLARE @XmlDocument nvarchar(1000) SET @XmlDocument = N' ...
-
它基本上是Windows中的已知错误。 https://bugreports.qt.io/browse/QTBUG-30541 https://doc-snapshots.qt.io/qt5-5.5/qtmultimedia-windows.html 不过,它应该适用于其他平台。 It basically is a known bug in windows. https://bugreports.qt.io/browse/QTBUG-30541 https://doc-snapshots.qt.io/qt5 ...
-
MethodBuilder不支持GetILGenerator方法(GetILGenerator method is not supported by MethodBuilder)[2022-02-25]
收到的异常是: [System.NotSupportedException:不支持指定的方法。]在GenericMethodBuilder.Main()的System.Reflection.Emit.TypeBuilderInstantiation.GetConstructors(BindingFlags bindingAttr):第26行 在GetConstructor调用。 发生这种情况是因为您尝试获取尚未构造的类型List构造函数。 要走的路是使用静态TypeBuilder.GetCo ... -
这是一个减少的repro: let f x (y:System.IComparable) = () let g = f 1 g 3 g "test" // not okay let g' : System.IComparable -> unit = f 1 g' 3 g' "test" // okay let g'' x = f 1 x g'' 3 g'' "test" // okay g:('a -> unit) when 'a :> System.IComparable我的例子中的g:('a - ...
-
在已经有.bind()的浏览器中运行此代码的唯一缺点是需要下载一些额外的代码。 当此代码在现代浏览器中运行时,它会命中第一个if语句并跳过其他所有内容。 如果已经支持.bind() ,则此polyfill不会替换现有功能。 它看到现有的功能已经存在,所以它什么都不做。 像这样的Polyfill很好用。 它们允许您为现代浏览器(而不是最小公分母)编码,同时仍支持旧版浏览器。 强烈建议使用这样的优质填料。 听起来你不清楚这个脚本是如何工作的。 它的作用如下: 它检查.bind()是否已在函数上可用。 如果是,则 ...
-
这是Object.entries的简单实现。 它适用于https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/entries中的所有示例 Object.entries = Object.entries || function(obj) { return Object.keys(obj).map(function(k) { return [k, obj[k]]; }); ...
-
正如您所描述的那样,问题在于第一个示例中的entityKey函数是不透明的,因为它的类型为Func而不是Expression。 但是,您可以通过实现Compose()方法来组合两个表达式来获得所需的行为。 我在这个问题中发布了实现compose的代码: 在Linq中使用Expression
>包含扩展名 。 使用Compose(),您的函数可以实现如下: public static List Load (this IQueryable entityQuery, ... -
你应该看看https://github.com/ircmaxell/password_compat 该库旨在提供与PHP 5.5附带的password_ *函数的向前兼容性。 You should take a look at https://github.com/ircmaxell/password_compat This library is intended to provide forward compatibility with the password_* functions that ship ...