更改远程URL动态jquery验证

时间:2016-12-28 20:38:28

标签: jquery jquery-validate

我想动态更改远程网址,当我填写输入时,正常工作,但是当我点击" load.php"按钮,它仍然加载" check.php"。帮助我。

这是我的代码

<script type="text/javascript"  src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript"  src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>

<form id="validate">
      <input id="testremote" name="testremote"  type="text" data-rule-remote="check.php" required data-msg-required="Please Fill" >
        <br/><br/>
      <input class="submit" type="submit" value="Submit">
</form>
<button onclick="changeurl('load.php');">Change URL(load.php)</button>
<button onclick="changeurl('test.php');">Change URL(test.php)</button>
<script>
$(function(){
$("#validate").validate();
});

function changeurl(a){
var x = $("#testremote");
x.attr("data-rule-remote",a);
}
</script>

1 个答案:

答案 0 :(得分:0)

如果您在开发工具中打开控制台,则会看到错误validate() is not a function或类似的内容。

此错误导致脚本执行因此错误而在此处结束,并且甚至未创建函数changeurl()

但为什么validate() is not a function? 这意味着包含库的链接出了问题。要解决此问题,只需将http替换为https

<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>

如果我没错,我认为如果其中一个资源是通过https加载http的其他资源,则会被忽略。但我不确定。

希望它对你有所帮助。