通过input将数据存入js
// An highlighted block
<div id="shuru">
<input type="text" id="txt">
<br>
<input type="button" id="btn" value="保存">
<br>
<p style="color: white">已经输入名单</p>
<br>
<textarea id="mingdan" disabled>
</textarea>
</div>
<div class="main">
<div class="button"><span>开始</span></div>
<div class="text"><span id='ko'></div>
</div>
js接收并且进行随机点名,点名一个删除一个名单
<script>
var names=[];
var length;
var val;
$(function(){
$("#btn").click(function(){
var name = $("#txt").val();
if( name != ""){
names.push(name);
$("#txt").val("");
$("#mingdan").val(names);
}
});
$('.button').toggle(function(){
$(this).css({'color':'#f00'}).html('停止');
ydm=setInterval(function(){
var index=Math.floor(Math.random()*names.length);
val=names[index];
$('#ko').css({'color':'#9fc'}).html(val);
},50)},
function(){
for(var i=0;i<names.length;i++){
if(names[i]==val){
names.splice(i,1);
continue;
}
};
$("#mingdan").val(names);
$(this).css({'color':'#fff'}).html('开始');
$('#ko').css({'color':'#f00'});
clearInterval(ydm);
})
});
</script>