小编Kis*_*lin的帖子

为一个集团文字上色,使其看起来像法国国旗

我在网页上有一个给定的文本块,我想使用javascript和JQuery使它看起来像法国国旗(蓝/白/红).

现在我尝试了以下代码:JSFiddle

或者,如果您更喜欢Stackoverflow片段:

jQuery(function ($) {
  // Calculates the text width in <p>
	var html_cur = $('.loremipsum').html();
	var html_calc = '<span>' + html_cur + '</span>';
	$('.loremipsum').html(html_calc);
	var width = $('.loremipsum').find('span:first').width(); 
  
	var color_width = Math.floor(width / 3), // Width of each color
		text = $( ".loremipsum" ).text(), // Text of <p>
		array = [], // Array containing each sentences 
		sentence = '', // Current sentence
		sentence_width = 0; // Current sentence width

	for(var i = 0; i < text.length; i++) …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

3
推荐指数
1
解决办法
266
查看次数

比较集合中的对象

现在我有这个Java代码

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public class Dummy {

    private String value;

    public Dummy(final String value) {
        this.value = value;
    }

    public boolean equals(final Object that) {
        return that instanceof Dummy && Objects.equals(value, ((Dummy) that).value);
    }

    public int hashcode() {
        return Objects.hash(value);
    }

    public static void main(final String... args) {
        final Set<Dummy> dummies = new HashSet<>();
        dummies.add(new Dummy("toto"));
        System.out.println(dummies.contains(new Dummy("toto")));
    }
}
Run Code Online (Sandbox Code Playgroud)

输出是"假的",我应该通过只更改一个字符将其更改为"true",但我完全不知道如何做到这一点......任何想法?谢谢.:)

java hash set

0
推荐指数
1
解决办法
1538
查看次数

标签 统计

css ×1

hash ×1

html ×1

java ×1

javascript ×1

jquery ×1

set ×1