javascript - jQuery:突出显示 div 框 onload

标签 javascript jquery html onload highlight

此 jQuery 代码将在单击时突出显示 div 框。

我想在加载时获得亮点,我该怎么做?

<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<style type="text/css">
div { margin: 0px; width: 100px; height: 80px; background: #666; border: 1px solid black; position: relative; }
</style>

  <script>
  $(document).ready(function() {

$("#div1").click(function () {
      $(this).effect("highlight", {}, 3000);
});

  });
  </script>
</head>
<body">
  <div id="div1"></div>
</body>
</html>

最佳答案

highlight 的语句放在 document.ready 中,与绑定(bind) click 事件的级别相同。

Live Demo

$(document).ready(function() {
      $("#div1").effect("highlight", {}, 3000); //this will highlight on load
      $("#div1").click(function () {
           $(this).effect("highlight", {}, 3000);
      });    
 });

关于javascript - jQuery:突出显示 div 框 onload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15853619/

相关文章:

javascript - ReactJS:导入headroom后出现错误

javascript - 我可以实例化一个变量,但稍后再为 value 赋值吗?

javascript - 谷歌图表不显示

jquery - div 设置为 100% 宽度和 100% 高度,但不继承父 div 的大小

javascript - 是否可以禁用 Firebase 自动转换为 native 数组?

javascript - 如何将 orderCells 设置到数据表的中间行?

javascript - Chrome 应用程序将 JSON 作为字符串读取

html - 使用 css 调整列大小时的怪癖

Internet Explorer 上的 Javascript 语法错误

html - 电子邮件设计 : Text over background image