<h2 style="margin-left:80px;display:inline;margin:">分值結(jié)果</h2><button type="button" class="btn btn-danger" id="additem">添加一個分值范圍</button>
<div id="cc">
<div id="first">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-input-readonly"> 得分范圍</label>
<div class="col-sm-9">
<input type="text" name="scopeA[]" class="col-xs-1 col-sm-1" placeholder="0" onblur="checkok(this)">
<input type="text" name="scopeB[]" class="col-xs-1 col-sm-1" placeholder="30" onblur="checkok(this)" >
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-input-readonly"> 結(jié)果</label>
<div class="col-sm-9">
<textarea name="result[]" style="width:500px;height:100px">您好,你有輕度抑郁</textarea>
</div>
</div>
</div>
</div>
<script>
$(function(){
var html=$("#first").html();
$("#additem").click(function(){
$("#cc").append(html);
});
})
function checkok(obj){
obj.value=obj.value.replace(/[^0-9]+/,'')
if (obj.value=='') {
alert('請輸入數(shù)值');
obj.value=0;//設默認值
obj.focus();
}
}
</script>
//另外一種方法,onblur不好用
<input type='text' onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();" />