javascript 我想从输入文本字段中获取字符串并与某个字符串进行比较,如果它是真的发送到某个 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17176310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:23:16  来源:igfitidea点击:

i want get string from Input text field and compare to some string, if it?s true send to some url

javascripturlequalsgetelementbyidonsubmit

提问by user2497695

i still have problem in my code. i want the Java get the string froom the input text field and compare to another string, it′s true, send to some url. i did this code, but it doesn′t work.

我的代码仍然有问题。我希望 Java 从输入文本字段中获取字符串并与另一个字符串进行比较,这是真的,发送到某个 url。我做了这个代码,但它不起作用。

<input type="text" name="procura" id="pro" value="" />


 <script language="JavaScript">
 function ver(){
    var pp = document.getElementById('pro').value;
  if (pp.equals('advogados'))
 {
     window.location = "http://www.jornalexemplo.com.br"
     //do something
 };
 };


  </script>

  </div></td>
                    <td width="399"><input type="submit" name="Busca" id="Busca"    value="AWR Procura" onsubmit="ver()"; /></td>

回答by NFE

Change the type of buttoninstead of submit. call that method onClick.

更改 的类型button而不是submit。调用那个方法onClick

<input type="button" name="Busca" id="Busca"    value="AWR Procura" onClick="ver()"; />

submitonly use when you need to send data on server.

submit仅在您需要在服务器上发送数据时使用。

回答by srikanth shanigaram

Instead of using pp.equals,use

而不是使用pp.equals,使用

if(pp == 'advogados') 

then it works properly. and change the submit button to button and call the function

然后它正常工作。并将提交按钮更改为按钮并调用该函数