日期:2014-05-17 浏览次数:20878 次
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>test</title> <style> td{ padding:20px; } </style> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right"> <textarea name="textarea" id="text1" cols="60" rows="6"></textarea></td> <td align="center"><input type="button" name="button" id="button" value="转换" style="width:100px; height:100px" onClick="text3()"></td> <td><textarea name="textarea2" id="text2" cols="60" rows="6"></textarea></td> </tr> <tr> <td colspan="3" align="center"><textarea name="textarea3" id="text3" cols="80" rows="6"></textarea></td> </tr> </table> </body> </html> <script> function $(id){ return document.getElementById(id); } function text3(){ var text1=$('text1').value; var textArray1=text1.split('\n'); var text2=$('text2').value; var textArray2=text2.split('\n'); var colArray1,colArray2; var resultStr=''; for(var i1 in textArray1){ colArray1=textArray1[i1].split(' '); for(var i2 in textArray2){ colArray2=textArray2[i2].split(' '); if(colArray1[1]==colArray2[1]){ resultStr+=colArray1[1]+' [a]'+colArray1[0]+'[/a] [bb]'+colArray2[0]+'[/bb]\n'; } } } $('text3').value=resultStr; } </script>