如何根据计时器更改div的内容 How to change contents of a div based on timer
好的脚本! 是否有可能有“Tip01”,“Tip02”,“Tip03”等,直到“Tip09”,再次从“Tip01”开始,而不是随机的?感谢。答案 0 :(得分:2)
您可以移除该代码的随机部分,并在到达数组末尾时将0
的值重置为var tips = [
"Tip 01",
"Tip 02",
"Tip 03",
"Tip 04",
"Tip 05",
"Tip 06",
"Tip 07",
"Tip 08",
"Tip 09",
];
var i = 0;
setInterval(function() {
$("#tip").html(tips[i]);
i++ ;
if(i == tips.length){
i = 0;
}
}, 500);
:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="tip"></div>
&#13;
Repository:
@Transactional
public interface Local_Repository extends JpaRepository<LocalModel,Long> {
}
Service:
public interface Local_Service {
public List<LocalModel> findAll();
public LocalModel findById(Long id);
public LocalModel findBymo(String mo);//this is the function I added
}
Implementation:
@Service
public class Local_Impl implements Local_Service {
@Autowired
private Local_Repository repository;
@Override
public List<LocalModel> findAll() {
List<LocalModel> cities = (List<LocalModel>) repository.findAll();
return cities;
}
@Override
public LocalModel findById(Long id) {
LocalModel city = repository.findOne(id);
return city;
}
@Override //this throws error
public LocalModel findBymo(String mo) {
LocalModel city=repository.findBymo(mo);
return null;
}
&#13;
答案 1 :(得分:1)
const tips = [
"Tip 01",
"Tip 02",
"Tip 03",
"Tip 04",
"Tip 05",
"Tip 06",
"Tip 07",
"Tip 08",
"Tip 09",
];
let i = 0;
setInterval(function() {
document.querySelector('#tip').textContent = tips[i];
i++;
if (i === tips.length) i = 0;
}, 300);
&#13;
<div id="tip"></div>
&#13;