强制 td换行 不影响 td中值向后传递 (不会变化)

本文介绍了一个使用PHP和JavaScript实现的表单文本处理方法,能够根据不同浏览器(IE与Firefox)的特点,将输入框和表格单元格中的文本进行转换,并在不同元素间传递文本数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php
$txt_value = $_GET['td_2_input'];
$txt_value_area = str_replace("<br>","/r/n",$txt_value);//for  be_input_txt_area
$txt_value = str_replace(" ","&nbsp;",$txt_value);//for td show blank line start

$txt2_value = $_GET['td_to_txt'];
//$txt2_value = str_replace(" ","&nbsp;",$txt2_value);
$txt2_value = str_replace("<BR>","/r/n",$txt2_value);//ie <BR>
$txt2_value = str_replace("<br>","/r/n",$txt2_value);//ff <br>
?>
<html>
    <head>
        <script>
            function inputtable(){
                txt_area = document.getElementById("txtarea").value;
                
                /*check ie or firefox*/
                var Version = navigator.appVersion;
                //alert(Version);
                check_Version = Version.substr(17,4);
                if (check_Version == "MSIE")
                {
                    /*change  blank in ie*/
                    //alert("ie");
                     var reg = new RegExp("/r/n","g");
                     txt_area = txt_area.replace(reg,"<br>");
                }else{
                    /*change blank  in firefox*/
                    //alert("firefox");
                     var reg = new RegExp("/n","g");
                     txt_area = txt_area.replace(reg,"<br>");
                }
                alert(txt_area);
                window.location = "table_textarea_br.php?td_2_input="+txt_area;
            }
            function tdtotxtarea(){
                td_value = document.getElementById("td_2").innerHTML;
                var reg = new RegExp("&nbsp;","g");
                 td_value = td_value.replace(reg," ");
                window.location = "table_textarea_br.php?td_to_txt="+td_value;
            }

 

           //从php中转换过的 txt_value_area  在js中也需判断/r/n和/n

            function check_ff_br(){
                txt2_value = document.getElementById("txtarea_2").value;
                
                
                var Version = navigator.appVersion;
                //alert(Version);
                check_Version = Version.substr(17,4);
                if (check_Version == "MSIE")
                {
                    /*change  blank in ie*/
                    //alert("ie");
                     var reg = new RegExp("/r/n","g");
                     txt2_value = txt2_value.replace(reg,"xxxx");
                }else{
                    /*change blank  in firefox*/
                    //alert("firefox");
                     var reg = new RegExp("/n","g");
                     txt2_value = txt2_value.replace(reg,"xxxx");
                }
                
                
                alert(txt2_value);
            }
        </script>
    </head>
    <body>
        <textarea id = "txtarea" style= "height:10%;width:10%;"></textarea>
        <input id = "be_input_txtarea"  type = "button" value = "pushin" onclick="inputtable();"></input>
        <textarea id ="txtarea_2" style= "height:10%;width:10%;"><?php echo $txt_value_area;?></textarea>
        <input type = "button" value = "txt2" onclick ="check_ff_br();"></input>
        <br/>
        <br/>
        <br/>
        <table border = "1" style = "width:30%;table-layout:fixed;">
            <tr>
                <td style="width:30%">111</td>
                <td id = "td_2"  style="width:40%;word-wrap:break-word;"><?php echo $txt_value;?></td>
                <td style="width:30%;">333</td>
            </tr>
        </table>
        <input type ="button" value = "td_to_txt" onclick = "tdtotxtarea();"></input>
        <textarea style= "height:10%;width:30%;"><?php echo $txt2_value;?></textarea>
    </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值