HTML textarea show br

时间:2017-09-23 08:47:35

标签: javascript html

我有一个HTML格式的textarea。在textarea中,空白行显示为br。

我试着拥有一些文字的价值。和发布一起发布。我收到PHP后。我把一些文本的值改为变量,我得到了get。

像这样:

a<br />b c

代码(使用javascript发布):

<script type="text/javascript">

        function nl2br (str, is_xhtml) {
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}

        function menusec(secilen){

            var deger = secilen.options[secilen.selectedIndex].value;
            var urunadi = document.getElementById("okulueua").value;
            var urunfiyati = document.getElementById("okulueuf").value;
            var kargofiyati = document.getElementById("okuluekf").value;
            var aciklama = nl2br(document.getElementById("okulueat").value);

            alert(aciklama);

            window.location.href = "okulue.php?menu=" + deger + "&urunadi=" + urunadi + "&urunfiyati=" + urunfiyati + "&kargofiyati=" + kargofiyati + "&aciklama=" + aciklama;

        }

    </script>

代码(用PHP获取):

<?php

    if (isset($_GET['menu'])) {

        $secilendeger = filter_input(INPUT_GET, "menu");

        $urunadiget = filter_input(INPUT_GET, "urunadi");

        $urunfiyatiget = filter_input(INPUT_GET, "urunfiyati");

        $kargofiyatiget = filter_input(INPUT_GET, "kargofiyati");

        $aciklamaget = filter_input(INPUT_GET, "aciklama");

        echo($aciklamaget);

        ?>

        <script type="text/javascript">

            function br2nl($content){

                $content = str_ireplace("<br /> ", "\n", $content);
                return $content;

            }

            function br2nl1($input){
    return preg_replace('/<br(\s+)?\/?>/i', "\n", $input);
}

            document.getElementById("menusecme1").style.width = "315px";

            document.getElementById("okulueua").value = "<?php echo($urunadiget); ?>";

            document.getElementById("okulueuf").value = "<?php echo($urunfiyatiget); ?>";

            document.getElementById("okuluekf").value = "<?php echo($kargofiyatiget); ?>";

            document.getElementById("okulueat").value = "<?php echo($aciklamaget); ?>";

            $('select[name^="ms1"] option[value="<?php echo($secilendeger); ?>"]').attr("selected","selected");

        </script>

代码(HTML):

<input type="text" class="okulueuat" name="okulueua" id="okulueua">
<input type="text" class="okulueua2t" name="okulueua2" value="1000" readonly="yes">
<input type="text" class="okulueuft" name="okulueuf" id="okulueuf">
<input type="text" class="okuluekft" name="okuluekf" value="5" id="okuluekf">
<input type="submit" class="tamamb2" value="Tamam" name="submit">
<input type="button" class="iptalb2" value="İptal" onclick="location='okulul.php'">
<input type="file" name="okuluef[]" class="resimeklec" multiple="multiple">

<textarea id="okulueat" name="okuluea"></textarea>

我该如何解决这个问题?

我需要你的帮助。

注意:我的英语不好。对不起。我希望你明白。

1 个答案:

答案 0 :(得分:-1)

试试这个:

 <textarea>a&#13;&#10;b c</textarea>