jQuery- Detect change in the content of a SPAN field

后端 未结 2 1988
我寻月下人不归
我寻月下人不归 2021-02-07 18:18

I have the below piece of code which is used to simulate a text box:




        
相关标签:
2条回答
  • 2021-02-07 19:13

    i think this code will help you.

    $(document).ready( function() {
        $('#myId').bind( "contentchange", function(){
            alert("Changed");
        });
    
        $( "#btn" ).click( function () {
            $('#myId').html( "Value" ).trigger( "contentchange" );
        });
    });
    

    http://jsfiddle.net/RKLmA/192/

    0 讨论(0)
  • 2021-02-07 19:23

    You can use this event DOMSubtreeModified:

    $("span").on('DOMSubtreeModified', function () {
      alert("Span HTML is now " + $(this).html());
    });
    

    Snippet

    $(function () {
      $("a").click(function () {
        $("span").html("Hello, World!");
      });
      $("body").on('DOMSubtreeModified', "span", function () {
        alert("Span HTML is now " + $(this).html());
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <span>Hello</span>
    <a href="#">Click</a>

    0 讨论(0)
提交回复
热议问题