weixin_33724059 2017-03-23 12:07 采纳率: 0%
浏览 41

如何设置表单验证输入?

我有一个表格,需要设置表单验证输入:

<input type="text" name="telefon" required="" placeholder="Telefon numaranız" class="form-control">

但当我单击“提交表单”时总是没反应。这是我的JavaScript代码:

<script>
function uyem() {
      jQuery.ajax({
      type: 'POST',
      url: 'src/ajax/kayit.php',

      data: $('#uyelik-formu').serialize(),
      error:function(){ $('#sonuc').html("Bir hata algılandı."); },
      success : function (sonuc){
        if(sonuc == 'msms'){
          $("#mod-sms").modal('show');
        }
        if (sonuc == 'hatak'){
          $("#sonuc").html('<div role="alert" class="alert alert-danger alert-icon alert-icon-colored alert-dismissible"><div class="icon"><span class="mdi mdi-close-circle-o"></span></div><div class="message"><button type="button" data-dismiss="alert" aria-label="Close" class="close"><span aria-hidden="true" class="mdi mdi-close"></span></button><strong>Hata!</strong> E-posta yada telefon başka bir üye tarafından kullanılmakta.</div></div>');
        }
        if(sonuc == 'error'){
          $("#mod-error").modal('show');
          setTimeout(function() { location.reload() },4000);
        }
        if (sonuc == 'hata'){
          $("#sonuc").html('<div role="alert" class="alert alert-danger alert-icon alert-icon-colored alert-dismissible"><div class="icon"><span class="mdi mdi-close-circle-o"></span></div><div class="message"><button type="button" data-dismiss="alert" aria-label="Close" class="close"><span aria-hidden="true" class="mdi mdi-close"></span></button><strong>Hata!</strong> Geçerli bir e-posta ve telefon numarası giriniz.</div></div>');
          }
          }
      });
    }
    </script>
  • 写回答

2条回答 默认 最新

  • weixin_33728268 2017-03-23 12:10
    关注

    You have to tell your form if it needs to be submitted or not.

    <form onSubmit="uyem()"></form>
    
    function uyem() {
        $.ajax({});
    
        return false;
    }
    

    Returning false means do not submit form, while true means do submit.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办