删除Textarea后,JQuery停止工作

时间:2013-04-14 04:08:29

标签: jquery

我的页面中有以下JQuery。页面加载正常,代码最初工作。如果我编辑textarea字段,再次单击该字段不起作用。有没有办法在编辑textarea之后绑定JQuery功能?

$(document).ready(function() {
$("#prop_notes").dblclick(function() {
    var timestamp = '2013-04-01 20:40:00';
    var userid = '1';
    var username = 'Jim Williams';
    if ($('#prop_notes').val() == '') {
        $("#prop_notes").text("Timestamp: " + timestamp + "\nUser ID: " + userid + "\nUser: " + username);
    }
    else {
        $("#prop_notes").text($("#prop_notes").text() + "\n\n- - - - - - - - - - - - - - - - - - - -\n\nTimestamp: " + timestamp + "\nUser ID: " + userid + "\nUser: " + username);
    }
});

});

可重复的行为小提琴:http://jsfiddle.net/njgray/MxPNX/1/

1 个答案:

答案 0 :(得分:0)

尝试使用.val()代替.text()http://jsfiddle.net/sXkPE/3/

$(document).ready(function () {
    $("#prop_notes").on('dblclick', function () {
        var timestamp = '<?php echo $timestamp; ?>';
        var userid = '<?php echo $user_id; ?>';
        var username = '<?php echo $user_full_name; ?>';
        if ($('#prop_notes').val() == '') {
            $("#prop_notes").val("Timestamp: " + timestamp + "\nUser ID: " + userid + "\nUser: " + username);
        } else {
            $("#prop_notes").val($("#prop_notes").val() + "\n\n- - - - - - - - - - - - - - - - - - - -\n\nTimestamp: " + timestamp + "\nUser ID: " + userid + "\nUser: " + username);
        }
    });
});