简体   繁体   English

加载 div 时加载 JavaScript?

[英]Loading JavaScript when div has loaded?

I have a script that will reload the page (content) to a random DIV How do I implement this so that the script loads after the div is loaded?我有一个脚本,可以将页面(内容)重新加载到随机 DIV 我如何实现这一点,以便在加载 div 后加载脚本?

I have the following code ready:我准备好了以下代码:

<script>  
$(document).ready(function() {
   $("#getAssignment").click(function() {
      var $divs = $(".assignment");
      if ($divs.length > 0) {
         window.location.hash = "#" + $divs[ Math.floor(Math.random() * 
         $divs.length) ].id;
      }
  });
});    
</script>

$("div").load(function(){
    blah();
});

This will do what you wanted, but it does not make sense though, since div is not like an image or <script> or a page.这会做你想要的,但它没有意义,因为div不像图像或<script>或页面。 (You can't really "load" a <div> anyway.) (无论如何,你不能真正“加载”一个<div> 。)

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

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