日期:2014-05-17  浏览次数:20878 次

求一个效果的对比显示
-----------------------------------------------------
2120844 DJ小罗Remix这该死的温柔DISCO
2120843 lucky_twice-魔法项链第一首-DJ-舞曲-慢摇
2120842 Beautiful_Girls_(DJ→梦←Extended_Remix)
2120841 DjRuico_FunkyHouse_Remix
----------------------------------------------------
OKNDR1 DjRuico_FunkyHouse_Remix
DGERR2 lucky_twice-魔法项链第一首-DJ-舞曲-慢摇
EGDSF3 DJ小罗Remix这该死的温柔DISCO
EEEED4 Beautiful_Girls_(DJ→梦←Extended_Remix)
--------------------------------------------------

要实现的效果为:
DJ小罗Remix这该死的温柔DISCO [a]2120844[/a] EGDSF3  
lucky_twice-魔法项链第一首-DJ-舞曲-慢摇 [a]2120843[/a]DGERR2
Beautiful_Girls_(DJ→梦←Extended_Remix) [a]2120842[/a]EEEED4
DjRuico_FunkyHouse_Remix [a]2120841[/a][b]OKNDR1[b]

其实就是把,A和B记录对比,拿名称做一个唯一的对比,

我想到思路可不知道用什么代码做好。JS 还是ASP 还是PHP

------解决方案--------------------
HTML code

<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>