单击图像时jQuery shuffle div

时间:2022-08-26 20:27:48

I am trying to use a button as an image, will shuffle a block of text

我正在尝试使用按钮作为图像,将随机播放一段文本

Sorry if this is a very basic question, I'm just having trouble applying it to my current jQuery

很抱歉,如果这是一个非常基本的问题,我只是将它应用于我当前的jQuery

1 个解决方案

#1


0  

There seem to be some bugs in the opening and closing tags of your .headline1 class. You first need to properly define the refresh click function by defining the id like $('#refresh').click(). I assume you need something similar as your solution:

您的.headline1类的开始和结束标记中似乎存在一些错误。首先需要通过定义像$('#refresh')的id来正确定义刷新点击功能。单击()。我假设您需要与解决方案类似的东西:

$(function () {
 $('#refresh').click(function() {
var parent = $(".headline1");
var divs = parent.children();
while (divs.length) {
       parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);
     }
  });
});

Check out this FIDDLE.

看看这个FIDDLE。

#1


0  

There seem to be some bugs in the opening and closing tags of your .headline1 class. You first need to properly define the refresh click function by defining the id like $('#refresh').click(). I assume you need something similar as your solution:

您的.headline1类的开始和结束标记中似乎存在一些错误。首先需要通过定义像$('#refresh')的id来正确定义刷新点击功能。单击()。我假设您需要与解决方案类似的东西:

$(function () {
 $('#refresh').click(function() {
var parent = $(".headline1");
var divs = parent.children();
while (divs.length) {
       parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);
     }
  });
});

Check out this FIDDLE.

看看这个FIDDLE。