JS如下:
/*选择开始复制位置*/
$(document).ready(function(){
$("table").on("click","td[scode]",function(){
$("table td[scode]").attr("class","");
$(this).attr("class","inputred");
});
});
function cellkeydown(event) {
if (event.ctrlKey && event.keyCode == 86) {
var ss = document.getElementById("copyText");
ss.focus();
ss.select();
// 等50毫秒,keyPress事件发生了再去处理数据
setTimeout("dealwithData()",50);
}
}
/*粘贴数据*/
function dealwithData(event) {
var ss = document.getElementById("copyText");
ss.blur();
var a=$("table td[class='inputred']");
var tdindex=a.index();
var chooseinputlenght=$("table td[inputname]").length;
var trindex=a.parent("tr").index();
var tablea=a.parent("tr").parents("tbody");
var str= ss.value; //获取剪切板数据
if(chooseinputlenght<=0){
alert("请选择一个输入框!");return;
}
var hang = str.split("\n");
for(var i=0;i<hang.length-1;i++){
var tmpa=hang[i].split("\t");
var tmpb=new Array();
for(var k=0;k<tmpa.length;k++){
tmpb.push(tmpa[k]);
}
tablea.find("tr").eq(trindex+i).each(function(a){
var jk=0;
$(this).find("td").each(function(j){
if(j>=tdindex&&jk<=tmpb.length-1){
var tmpaaa=$(this);
var value=$.trim(tmpb[jk]).replace(/,/g,"");
if(tmpaaa.find("select option").size()>0){
tmpaaa.find("select option").each(function(){
if($(this).text()==value){
$(this).attr("selected",true);
}
});
}else{
tmpaaa.attr('value',value);
tmpaaa.text(value);
}
jk++;
}
});
});
}
}
body如下:
<body οnkeydοwn="return cellkeydown(event)">
<textarea id="copyText" style="position: absolute; top: -100000px; left: -100000px;" ></textarea>
<table id="righttbody">
<c:forEach var="list" items="${lists}" varStatus="inx">
<tr>
<td scode="" class="">
<select disabled name="arr.result_value" id="eva_results${inx.count}" οnchange="changezd(this,${inx.count})" >
<option value="">请选择</option>
</select>
</td>
<td scode="" value="${list.score}" class="">
<fmt:formatNumber value ="${list.score}" pattern="#0.00" />
</td>
<td scode="" class="">
<s:if test="${fn:length(list.sco_basis)>30 }">
${fn:substring(list.sco_basis,0,25)}...
</s:if>
<s:else>
${list.sco_basis}
</s:else>
</td>
<td scode="" class="">
<s:if test="${fn:length(list.fvsco_basis)>30 }">
${fn:substring(list.fvsco_basis,0,25)}...
</s:if>
<s:else>
${list.fvsco_basis}
</s:else>
</td>
</tr>
</table>
</body>