通过jquery Form.append填充Textarea

时间:2014-01-03 11:10:06

标签: jquery textarea

我正在尝试通过jquery填充textarea我可以插入值和填充输入但textarea我不能。这是代码。

eventClick: function(calEvent, jsEvent, view) {

        var form = $("<form class='form-inline'><label>&nbsp;</label></form>");
        form.append("<label>Titulo&nbsp;</label><input autocomplete=off type=text name='title' value='" + calEvent.title + "' /> <br />");
        form.append("<label>Local &nbsp;</label><input autocomplete=off type=text name='local' value='" + calEvent.local + "' /> <br />");
        form.append("<label>Descrição&nbsp;</label><textarea autocomplete=off type=text name='descricao' value='" + calEvent.descricao + "'/><br />");
        form.append("<label>Acompanhante&nbsp;</label><input autocomplete=off type=text name='acompanhante' value='" + calEvent.acompanhante + "' /> <br /> ");
        form.append("<button type='submit' class='btn btn-small btn-success'><i class='icon-ok'></i> Guardar</button>");

        var div = bootbox.dialog(form,
            [
            {
                "label" : "<i class='icon-trash'></i> Remover",
                "class" : "btn-small btn-danger",
                "callback": function() {
                    var decision =confirm("Tem a certeza que quer remover?"); 
                if (decision) {
                $.ajax({
                type: "POST",
                url: "delete_eventsagendapessoal.php",

                data: "&id=" + calEvent.id
                });

                    calendar.fullCalendar('removeEvents' , function(ev){
                        return (ev._id == calEvent._id);

                    })}
                }
            }
            ,
            {
                "label" : "<i class='icon-remove'></i> Fechar",
                "class" : "btn-small"
            }
            ]
            ,
            {
                // prompts need a few extra options
                "onEscape": function(){div.modal("hide");}
            }
        );

        form.on('submit', function(){
            calEvent.title = form.find("input[name=title]").val();
            calEvent.local = form.find("input[name=local]").val();
            calEvent.descricao = form.find("textarea[name=descricao]").val();
            calEvent.acompanhante = form.find("input[name=acompanhante]").val();
             var start = $.fullCalendar.formatDate(calEvent.start, "yyyy-MM-dd HH:mm:ss");
             var end = $.fullCalendar.formatDate(calEvent.end, "yyyy-MM-dd HH:mm:ss");
              $.ajax({
url: 'update_eventsagendapessoal.php',
data: 'title='+ calEvent.title +'&start='+ start +'&end='+ start +'&id='+ calEvent.id +'&local='+ calEvent.local +'&descricao='+ calEvent.descricao +'&acompanhante='+ calEvent.acompanhante,
type: "POST",
success: function(json) {
bootbox.alert("Modificado !");

}
});

1 个答案:

答案 0 :(得分:0)

不是

<textarea autocomplete=off type=text name='descricao' value='" + calEvent.descricao + "'/>

这是

<textarea name="descricao">' + calEvent.descricao + '</textarea>

如果您查找对textarea的任何引用,也许通过Google搜索“textarea示例”,您就会发现问题。

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#Example

.val("some content");适用于textarea。