我有一个HTML按钮:
<button>
<img id = "click-me" src="https:..." alt="Add to List" style="width: 50px"/>
</button>
Run Code Online (Sandbox Code Playgroud)
单击时,应执行此JQuery代码:
$(function () {
$("#click-me").click(function () {
document.getElementById('list').style.backgroundColor = "red";
});
});
Run Code Online (Sandbox Code Playgroud)
但是,不要按照我想要的方式执行操作,单击按钮会将我发送到我网站的另一页.我怎么阻止这个?谢谢
编辑:
这是页面的完整html:
<div class="form">
<h1>Create A Meeting</h1>
<%= form_for(@newevent) do |f| %>
<%= f.text_field :name, :placeholder => "Title" %>
<!--< f.collection_select :location, Location.all, :id, :locName %> FOR WHEN LOCATIONS ARE A THING-->
<%= f.text_field :description, :placeholder => "Short Description" %>
<div>
<h2>Who's involved?</h2>
<p>select a colleague to compare their calendar with yours</p>
<%= f.collection_select …Run Code Online (Sandbox Code Playgroud) 我正在为游戏中的玩家生成一些随机的x和y坐标:
var xcoordRed = Math.floor((Math.random() * 790) +1);
var ycoordRed = Math.floor((Math.random() * 400) +1);
Run Code Online (Sandbox Code Playgroud)
但我需要排除xcoordRed范围325 - 375和ycoordRed 150 - 250.
我将如何有效地做到这一点?
我想要一个哈希值,该值包含从1到18的整数作为键。我希望哈希看起来像这样:
myHash = Hash.new
myHash[1] = "free"
myHash[2] = "free"
...
myHash[18] = "free"
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更好的方法可以做到这一点,例如使用for循环。将类似:
myHash = Hash.new
for i in 1..18
myHash[i] = "free"
Run Code Online (Sandbox Code Playgroud)
工作,还是只创建18个称为i?