我想知道从同一个组件访问我的渲染函数中的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) 如何为HTML"开始"属性添加样式?
即使我将样式应用于整个有序列表标记,我也无法定位该数字.
//CODE:
<ol start="50">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
这是我解决问题的代码.但它似乎真的很粗暴.有没有优化/优雅的方式来写这个?
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)