gpt4 book ai didi

javascript - jquery 不在 chrome 中运行,在 ff 中运行

转载 作者:行者123 更新时间:2023-12-03 10:35:37 28 4
gpt4 key购买 nike

我一直在 ff 中构建和测试,现在在 chrome 中检查。除了 jquery 不运行之外,一切都运行良好。我似乎记得以前遇到过这个问题,但我不记得如何解决它。

我正在使用 Rails 应用程序,这是我想要运行的脚本:

已编辑

页面加载时会出现警报,但就绪函数永远不会执行。希望这能稍微缩小问题范围。

<script>
alert("hi")
$(document).ready(function () {
var theButton = $('#back-to-top');
var theButtonWidthOverTwo = theButton.width()/2;
theButton.css('top', $(window).height()-60);
theButton.css('right', $(window).width()/2-theButtonWidthOverTwo);
theButton.on("click", function() {
$('html, body').animate({scrollTop: 0}, "fast");
});

$(window).resize(function () {
theButton.css('top', $(window).height()-60);
theButton.css('right', $(window).width()/2-theButtonWidthOverTwo);
});
$("#club-posts-table").tablesorter();
});
</script>

Tablesorter 来自同名插件(作为 gem 安装)。

还有一个具有简短功能的按钮:

<button id="back-to-top" class="pink" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="position: fixed;bottom:0;z-index: 10; width: 240px;opacity: 0.3;">Back To Top</button>

所以基本上这些东西都不能在 Chrome 中运行。我还尝试将脚本移动到实际的 js 文件中,以便它将成为 Assets 管道的一部分,但它不起作用。除了 Tablesorter 之外,ready 函数和按钮中的代码不需要任何帮助来运行。

编辑2整个文件:

<div id="container-new-admin">


<button class="pink" onclick="window.location='<%= session[:back_button_url]%>';" style="width:200px;position:relative;margin:10px auto">Back</button>

<% if @posts_array != nil %>
<h1 style="text-align: center">All Posts By Members of <%= get_club_name_by_id %></h1>

<table id="club-posts-table" class="tablesorter">
<thead>
<td>Poster</td>
<td>Thumbnail</td>
<td>Content</td>
<td>Num Comments</td>
<td>Num Elevates</td>
<td>Date Posted</td>
</thead>
<tbody>
<% @posts_array.each do |p| %>
<tr>
<td><%= p.user.username %></td>
<td><a href="/post/<%= p.id %>" target="_blank"><%= load_image_only_if_exists(p) %></a></td>
<td><%= p.post_text %></td>
<td><%= p.comments.length %></td>
<td><%= p.post_elevations.length %></td>
<td><%= p.created_at.strftime("%m/%d/%Y") %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<h1 style="text-align: center">Try again, using a club id this time...</h1>

<% end %>
<button id="back-to-top" class="pink">Back To Top</button>
</div>

<script>
****see above****
</script

最佳答案

我认为仅使用 css 来做到这一点会更容易。请在 jsFiddle 中找到演示.

onclick 处理程序也在演示中工作,但我认为最好在脚本中添加处理程序(如评论中建议的那样)。

//$(function(){$("#club-posts-table").tablesorter();});

$(document).ready(function () {
var theButton = $('#back-to-top');

/* works but css is even simpler - one line in css with :hover
var show = function() {
$(this).css('opacity','1.0');
};
var hide = function() {
$(this).css('opacity','0.3')
};

// hover(inHandler, outHandler)
theButton.hover(show, hide);
*/

/* works but hover is easier
theButton.on("mouseover", function() {
theButton.css('opacity','1.0')
});

theButton.on("mouseout", function() {
theButton.css('opacity','0.3')
});*/

theButton.click(function() {
$('html, body').animate({ scrollTop: 0 }, 'fast');
});
});
button {
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
color: #444;
min-width: 90px;
padding:5px;
margin: 5px 10px;
background-color: #fdfdfd;
border: 1px solid #cdcdcd;
cursor: pointer;
border-radius: 3px;
}

#back-to-top {
z-index: 10;
width: 240px;
max-width: 100%; /* Make it fit window if under 500px */
opacity: 0.3;
}

#back-to-top:hover {
opacity: 1.0;

}
.footer {
position: fixed;
/*background-color: blue;*/
text-align: center;
width: 100%;
bottom: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.

Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis
</div>
<div class="footer">
<button id="back-to-top" class="pink">Back To Top</button>
</div>

关于javascript - jquery 不在 chrome 中运行,在 ff 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28997270/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com