开发者

Parsing on the value to the wrong area

I have some codes like this. Result 1 works fine, but result 2 displays the input from result 1.

Can someone please help me out?

JS:

$(document).ready(function(){
    exampleResult1();   
    function exampleResult1() {
        $(".exampleResult1 .result").text(
            '<开发者_如何学编程;div>' + $(".content").val() + '</div>'
        )
    }
    $(".exampleResult1 input").keyup(exampleResult1);


    exampleResult2();   
    function exampleResult2() {
        $(".exampleResult2 .result").text(
            '<div>' + $(".content").val() + '</div>'
        )
    }
    $(".exampleResult2 input").keyup(exampleResult2);

})

HTML:

<div class="exampleResult1">
    <p><input type="text" class="content"></p>
    Code: 
    <div class="code">
        <code><div class="result"></div></code>
    </div>
</div>

<div class="exampleResult2">
    <p><input type="text" class="content"></p>
    Code: 
    <div class="code">
        <code><div class="result"></div></code>
    </div>
</div>


Use Below Code :

 $(document).ready(function(){
    $('.exampleResult2 .content').keyup(function ()
    {
        $('.exampleResult1 .result').text($('.exampleResult1 .content').val());
    });

    $('.exampleResult2 .content').keyup(function ()
    {
        $('.exampleResult2 .result').text($('.exampleResult2 .content').val());
    });
 })

UPDATED

This is live Preview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜