Jquery 引导远程内容表单验证

Jquery 引导远程内容表单验证,jquery,validation,Jquery,Validation,我试图在引导模式中验证表单。我的代码运行良好,直到我尝试远程将表单加载到模式中。这是我没有远程加载的代码 请帮忙 <div class="modal fade" id="mymodal" tabindex="-1" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> &

我试图在引导模式中验证表单。我的代码运行良好,直到我尝试远程将表单加载到模式中。这是我没有远程加载的代码

请帮忙

<div class="modal fade" id="mymodal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close"  data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">My Modal </h4>
      </div>
      <div class="modal-body">
        <form id="myform" method="post" class="form-horizontal" action="">
          <div class="form-group">
            <label class="col-sm-4 control-label" for="firstname1">First name</label>
            <div class="col-sm-5"><input type="text" class="form-control" id="name" name="name" /></div>
          </div>
          <div class="form-group">
            <div class="col-sm-9 col-sm-offset-4"><button type="submit" class="btn btn-primary" name="signup1" value="Sign up">Submit</button></div>
          </div>
        </form>
      </div>
      <div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal"> Close </button></div>
    </div>
  </div>
</div>             

&时代;接近
我的情态
名字
提交
接近
$('#mymodal').on('show.bs.modal',function(){
$.get(“my_modal.htm”,函数(数据){
$('#mymodal').find('.modal content').html(数据);
$(“#myform”)。验证({
规则:{
姓名:{
要求:正确,
最小长度:2
}
},
信息:{
姓名:{
必填:“请输入名称。”,
minlength:jQuery.validator.format(“请,至少需要{0}个字符”)
}
}
});
$(“#按钮”)。单击(函数(){
if($('#myform').valid(){
警报(“表格有效”);
返回false;
}否则{
警报(“表单无效”);
}
});
});
})

问题可能出在您没有发布的js中。请向我们展示您在“远程加载”案例中使用的js代码。仅供参考。。。您可以将HTML、CSS、JS小提琴放在stackoverflow上,其中一个按钮位于输入问题的文本区域顶部。不需要js fiddle。这是我想到的,但无法让fiddle加载远程文件。我没有看到任何错误,快速查看它。有控制台消息吗?(如果我没记错的话,validate有一个调试模式!?)谢谢,这段代码很好。我只是想分享我的解决方案,因为我很难找到它。
$('#mymodal').on('show.bs.modal', function() {
$.get("my_modal.htm", function(data) {
$('#mymodal').find('.modal-content').html(data);
$("#myform").validate({
  rules: {
    name: {
      required: true,
      minlength: 2
    }
  },
  messages: {
    name: {
      required: "<i>Please enter name.</i>",
      minlength: jQuery.validator.format("Please, at least {0} characters are necessary")
    }
  }
});
$('#button').click(function() {
  if ($('#myform').valid()) {
    alert('form is valid');
    return false;
  } else {
    alert('form is not valid');
  }
});
});
})