小编Min*_*ack的帖子

我可以使用compareTo来排序整数和双精度值吗?

我可以使用compareTo来排序整数和双精度值吗?我的系统给了我一个错误,我不能在原始类型int上调用compareTo(int).有任何想法吗?

码:

public int compare(Object o1, Object o2) {  
Record o1C = (Record)o1;
Record o2C = (Record)o2;                
return o1C.getPrice().compareTo(o2C.getPrice());
}

class Record
    public class Record {
    String name;
    int price;    

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
}
Run Code Online (Sandbox Code Playgroud)

java

13
推荐指数
2
解决办法
3万
查看次数

如何将addClass添加到多个元素?

我正在使用这个javascript来为多个元素添加一个类.我试图引用多个div和addClass.它只适用于第一个.

使用Javascript

<script>            
            $(function(){           
            if ( $(window).width() < 230 ) {
              $('#item1').addClass('col1'); //max-width 80px

            }
            else 
                if ( $(window).width() >= 230 && $(window).width() < 330 ) {
              $('#item1').addClass('col2'); //max-width 180px

            }
            else 
           {
              $('#item1').addClass('col3'); //max-width 280px

            }

          });
        </script>
Run Code Online (Sandbox Code Playgroud)

如果我在页面上只有一个#item1但它似乎不想将类添加到同一div id中存在的多个项目,那么它正在工作.我甚至尝试将类添加到同一div类中存在的多个项而不是id.如果你能弄明白的话,任何一个都是mw的好解决方案.

我的HTML代码是

    <div id="item1" class="blue">
<label for="amount">Price range:</label>
<input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
<div class="slider-range"></div>
</div>

<div id="item1" class="blue">
<label for="amount2">Price range:</label>
<input type="text" id="amount2" style="border:0; color:#f6931f; font-weight:bold;"/>
<div class="slider-range2"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

一直试图弄清楚这几个小时,所以我想我会问是否有人可以指出我正确的方向.提前致谢.

html javascript css jquery

-2
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

html ×1

java ×1

javascript ×1

jquery ×1