jquery $(document).ready 事件不起作用

Mariowjf624 Mariowjf624 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有一个table,其中所有行除了表头都设为data class。
然后我在$(document).ready()事件中设定这些行的事件:

$(document).ready(function ()
{
$(".data").mouseenter(function ()
{
$(this).children().css("background-color", "#f1f1f1");
});

$(".data").mouseleave(function ()
{
$(this).children().css("background-color", "#ffffff");
});
});

结果事件不起作用,而当我在$(".data").mouseenter行之前加一个alert(),事件就起作用了。
看起来是document ready触发的时候有什么东西还没载入完成。请问有什么办法解决这个问题?总不能让用户每次都先点一下alert吧!

下面是我的事件作用于的table:

<table class="details ui-widget-content fullWidth">
<thead>
<tr>
<th>Machine Name</th>
<th>IP Address</th>
<th>State</th>
<th>Provision Type</th>
<th>Running</th>
<th></th>
</tr>
</thead>
<tbody data-bind="foreach: machines">
<tr class="data"> <td><span data-bind="text: ComputerName"></span></td>
<td><span data-bind="text: IPAddress"></span></td>
<td><span data-bind="text: State"></span></td>
<td><span data-bind="text: ProvisionType"></span></td>
<td><span data-bind="text: HasRunningServer"></span></td>
<td><a onclick="toggleImages(event)">Show</a></td>
</tr>
<tr class="data images"> <td colspan="6">
<table>
<tr>
<td>456</td>
</tr>
</table>

</td>
</tr>
</tbody>
</table>
...全文

相关推荐

chrome浏览器不支持onmouseleave事件的解决技巧

发现给div加的 onmouseleave事件在chrome 中不起效果,下面与大家分享下具体的解决方法,不会的朋友可以了解下哈,希望对大家有所帮助

weixin_38551059

jQuery(document).ready(function($) { });的几种表示方法

在写jquery的时候,因为平时用sublime text快捷键生成jQuery(document).ready(function($) { });,所以忘记了其他的几种表示方法,今天花了几分钟特意记录了一下。

qq_15704535

Jquery中$(document).ready(function(){ })函数的使用详解

Jquery是优秀的Javascrīpt框架,$是jquery库的申明,它很不稳定(我就常遇上),换一种稳定的写法jQuery.noConflict(); jQuery(document).ready(function(){}); 使用jQuery的好处是它包装了各种浏览器版本对DOM对象(javascript的DOM对象你应该知道吧,就是它了)的操作. 比如jquery写法:$(“div p”); // (1)$(“div.container”); // (2)$(“div #msg”); // (3)$(“table a”,context); // (4)$(“#myId”); //(5)

weixin_38692969

jQuery之$(document).ready()使用介绍

学习jQuery的第一件事是:如果你想要一个事件运行在你的页面上,你必须在$(document).ready()里调用这个事件。所有包括在$(document).ready()里面的元素或事件都将会在DOM完成加载之后立即加载,并且在页面内容加载之前。 If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as theDOM is loaded and before

weixin_38640242

全面解析jQuery $(document).ready()和JavaScript onload事件

主要介绍了全面解析jQuery $(document).ready()和JavaScript onload事件的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下

weixin_38559646
评论 3
收藏 已收藏
分享
返回顶部
Mariowjf624
JavaScript 87,984 成员 224,680 内容