小编won*_*nry的帖子

React,如何从同一个组件访问我的渲染函数中的DOM元素

我想知道从同一个组件访问我的渲染函数中的DOM元素的最佳实践是什么.请注意,我将在页面上多次渲染此组件.

例如

var TodoItem = React.createClass({
    ...
    render:function(){

        function oneSecLater(){
            setTimeout(function(){
            //select the current className? this doesn't work, but it gives you an idea what I want.
            document.getElementsByClassName('name').style.backgroundColor = "red";
                )}, 1000);
        }

        return(
            <div className='name'>{this.oneSecLater}</div>
        )



})
Run Code Online (Sandbox Code Playgroud)

javascript css jsx reactjs

23
推荐指数
2
解决办法
4万
查看次数

如何在使用start属性的有序列表中设置标记样式?

如何为HTML"开始"属性添加样式?

即使我将样式应用于整个有序列表标记,我也无法定位该数字.

//CODE:
<ol start="50">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>
Run Code Online (Sandbox Code Playgroud)



OUTPUT:

  1. 咖啡
  2. 牛奶

html css html-lists twitter-bootstrap

5
推荐指数
1
解决办法
270
查看次数

如何在10到99之间生成50个随机数,没有重复.

这是我解决问题的代码.但它似乎真的很粗暴.有没有优化/优雅的方式来写这个?

System.out.println("\n\nPart II: Let' put in a list of 50 random numbers between 10 to 99. No Duplicates!");

        Linkedlist l1 = new Linkedlist();
        Random rand = new Random(); 

        for(int i = 0; i < 50; i++){
            int num = rand.nextInt(89) + 10;//range between 10 and 99.
            while(true){
                if(!l1.search(num)){
                    l1.add(num);
                    break;
                }
                else
                    num = rand.nextInt(89) + 10;//recycle for new num 
            }//infinite loop until new non-duplicate random value is generated for the list. 

        }//for
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
2
解决办法
6587
查看次数

标签 统计

css ×2

html ×1

html-lists ×1

java ×1

javascript ×1

jsx ×1

reactjs ×1

twitter-bootstrap ×1