简体   繁体   中英

Display text or code content on a div while typing in the textbox like markdown

I want to display text or code content on a div while I am typing in the textbox like markdown. Here is how far I got.

Script to show the content on div

<script type="text/javascript">
$(document).ready(function () {
$('#title').keyup(function(e){
var keyed = $(this).val().replace(/[]/g, '');
$("#result").html(keyed);
});
});
</script>

html part

<form>
<input type="text" id="title" name="title"/>
</form>
<div id="result">
</div>

It is working. But I want that when user types <table> tag it should not take it as a input and should not display anything

The only character that shows when typing tags is the open tag. I wrote some code to handle that open tag when typed in.

   $(document).ready(function () {
$('#title').keyup(function(e){
    var keyed = $(this).val().replace(/[]/g, '');
    if(keyed == '<')
    {
        $('#title').keyup(function(e){
            var keyed = $(this).val().replace(/[]/g,'');
            $('#result"').html('<' + keyed);
        });
    }
    else
    $("#result").html(keyed);
 });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM