<bdo id='ATPQe'></bdo><ul id='ATPQe'></ul>
  • <legend id='ATPQe'><style id='ATPQe'><dir id='ATPQe'><q id='ATPQe'></q></dir></style></legend>

      <small id='ATPQe'></small><noframes id='ATPQe'>

      <i id='ATPQe'><tr id='ATPQe'><dt id='ATPQe'><q id='ATPQe'><span id='ATPQe'><b id='ATPQe'><form id='ATPQe'><ins id='ATPQe'></ins><ul id='ATPQe'></ul><sub id='ATPQe'></sub></form><legend id='ATPQe'></legend><bdo id='ATPQe'><pre id='ATPQe'><center id='ATPQe'></center></pre></bdo></b><th id='ATPQe'></th></span></q></dt></tr></i><div id='ATPQe'><tfoot id='ATPQe'></tfoot><dl id='ATPQe'><fieldset id='ATPQe'></fieldset></dl></div>
      <tfoot id='ATPQe'></tfoot>
      1. 如何检查表单输入是否有价值

        How to check if form input has value(如何检查表单输入是否有价值)
      2. <small id='0OOKv'></small><noframes id='0OOKv'>

            <i id='0OOKv'><tr id='0OOKv'><dt id='0OOKv'><q id='0OOKv'><span id='0OOKv'><b id='0OOKv'><form id='0OOKv'><ins id='0OOKv'></ins><ul id='0OOKv'></ul><sub id='0OOKv'></sub></form><legend id='0OOKv'></legend><bdo id='0OOKv'><pre id='0OOKv'><center id='0OOKv'></center></pre></bdo></b><th id='0OOKv'></th></span></q></dt></tr></i><div id='0OOKv'><tfoot id='0OOKv'></tfoot><dl id='0OOKv'><fieldset id='0OOKv'></fieldset></dl></div>

              <tfoot id='0OOKv'></tfoot>
                <tbody id='0OOKv'></tbody>
                <bdo id='0OOKv'></bdo><ul id='0OOKv'></ul>

                  <legend id='0OOKv'><style id='0OOKv'><dir id='0OOKv'><q id='0OOKv'></q></dir></style></legend>
                • 本文介绍了如何检查表单输入是否有价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试检查表单输入是否有任何值(无论该值是什么),以便我可以将该值附加到提交时的操作 URL(如果它确实存在).我需要在添加值之前添加参数的名称,并且只留下一个空白的参数名称,如P =",没有任何值会弄乱页面.

                  I'm trying to check if a form input has any value (doesn't matter what the value is) so that I can append the value to the action URL on submit if it does exist. I need to add the name of the param before adding the value, and just leaving a blank param name like "P=" without any value messes up the page.

                  这是我的代码:

                  function getParam() {
                  
                  // reset url in case there were any previous params inputted
                  
                      document.form.action = 'http://www.domain.com'
                  
                      if (document.getElementById('p').value == 1) {
                          document.form.action += 'P=' + document.getElementById('p').value;
                      }
                  
                      if (document.getElementbyId('q').value == 1) {
                          document.form.action += 'Q=' + document.getElementById('q').value;
                      }
                  
                  }
                  

                  和形式:

                  <form name="form" id="form" method="post" action="">
                      <input type="text" id="p" value="">
                      <input type="text" id="q" value="">
                      <input type="submit" value="Update" onClick="getParam();">
                  </form>
                  

                  我认为设置 value == 1 会做一个简单的存在,不存在检查,不管提交的值是什么,但我想我错了.

                  I thought setting value == 1 would do a simple exists, doesn't exist check regardless of what the submitted value was, but I guess I'm wrong.

                  另外,我正在使用 if 语句,但我认为这是糟糕的代码,因为我没有 else.也许,使用 switch 语句,虽然我不确定我将如何设置它.也许:

                  Also, I'm using if statements, but I believe that's bad code, since I don't have an else. Perhaps, using a switch statement, though I'm not sure how I would set that up. Perhaps:

                  switch(value) {
                      case document.getElementById('p').value == 1 :
                          document.form.action += 'P=' + document.getElementById('p').value; :
                      case document.getElementById('q').value == 1 :
                          document.form.action += 'Q=' + document.getElementById('q').value; break;
                  }
                  

                  推荐答案

                  var val = document.getElementById('p').value;
                  if (/^s*$/.test(val)){
                     //value is either empty or contains whitespace characters
                     //do not append the value
                  }
                  else{
                     //code for appending the value to url
                  }
                  

                  P.S.:它比检查 value.length 更好,因为 ' '.length = 3.

                  P.S.: Its better than checking against value.length because ' '.length = 3.

                  这篇关于如何检查表单输入是否有价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                    • <bdo id='UcONV'></bdo><ul id='UcONV'></ul>

                      <small id='UcONV'></small><noframes id='UcONV'>

                    • <tfoot id='UcONV'></tfoot>

                          <i id='UcONV'><tr id='UcONV'><dt id='UcONV'><q id='UcONV'><span id='UcONV'><b id='UcONV'><form id='UcONV'><ins id='UcONV'></ins><ul id='UcONV'></ul><sub id='UcONV'></sub></form><legend id='UcONV'></legend><bdo id='UcONV'><pre id='UcONV'><center id='UcONV'></center></pre></bdo></b><th id='UcONV'></th></span></q></dt></tr></i><div id='UcONV'><tfoot id='UcONV'></tfoot><dl id='UcONV'><fieldset id='UcONV'></fieldset></dl></div>
                              <tbody id='UcONV'></tbody>

                            <legend id='UcONV'><style id='UcONV'><dir id='UcONV'><q id='UcONV'></q></dir></style></legend>