简体   繁体   English

包含后的jQuery脚本不起作用

[英]jQuery script is not working after included

Hi there :) I Want to make registration form .... 您好:)我想填写注册表....

I already included jQuery... 我已经包含了jQuery ...

This is button id of my registration form -> #regfr 这是我的注册表的按钮ID- > #regfr

This script including: 1 html file; 该脚本包括:1. html文件; 1 script file succesfully; 脚本文件成功1个;

<script>
$("#regfr").click(function() {
$("#included").append().load("Model/html/reg_form.html");
$("#included_scripts").append().load("Model/functionJS/reg_form.js")
});
</script>

This is the included script after click #regfr 单击#regfr后,这是包含的脚本

$( document ).ready(function() {
$('body').on("click", "#regfr",function() {
$("#reganime").fadeIn( "slow" )
});

Note : Here I didn't closed $( document ).ready yet becouse I am using other scripts inside... And the scripts working well when i am including them directly on page load... #reganime is div from reg_from.html Console erros checked = 0 :在这里,我没有关闭的$(document)。就绪尚未becouse我使用里面的其他脚本...和脚本运作良好,当我直接包括它们在页面加载... #reganimereg_from.html DIV控制台错误已检查= 0

Questions: How to fix this ? 问题:如何解决?

Why included scripts after call are not working ?... 为什么通话后包含的脚本不起作用?...

Is the problem is maybe: I am using two functions on click #regfr ? 问题可能出在:我在单击#regfr时使用了两个功能吗?

How to refresh DOM of the page ? 如何刷新页面的DOM?

Loading JS code, while possible, is best avoided for a variety of reasons. 出于各种原因,最好避免加载JS代码。 Not least of all that it adds needless complexity. 最重要的是,它增加了不必要的复杂性。

Instead you can include the relevant JS code in the page on load and use delegated event handlers to attach logic to elements which are appended to the DOM at some arbitrary point in the future, something like this: 相反,您可以在加载时在页面中包含相关的JS代码,并使用委托的事件处理程序将逻辑附加到将来在任意任意点附加到DOM的元素上,例如:

<!-- place this just before </body> -->
<script>
  $("#regfr").click(function() {
    $("#included").append().load("Model/html/reg_form.html");
  });

  $('#included').on('click', "#regfr", function() {
    $("#reganime").fadeIn("slow");
  });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM