Javascript 从文本区域获取信息
我需要帮助从文本区域获取信息。当我点击一个名为Edit的链接时,它旁边包含注释的div将从div转换为textarea 我使用以下代码执行此操作:Javascript 从文本区域获取信息,javascript,jquery,Javascript,Jquery,我需要帮助从文本区域获取信息。当我点击一个名为Edit的链接时,它旁边包含注释的div将从div转换为textarea 我使用以下代码执行此操作: $(".edit").click( function(){ var id = parseInt($(this).attr('id').split('_')[1]); //returns the unique integer //edit only the div with that integer assigned $('#edit_note_'+i
$(".edit").click( function(){
var id = parseInt($(this).attr('id').split('_')[1]); //returns the unique integer
//edit only the div with that integer assigned
$('#edit_note_'+id).replaceWith(function() {
return $("<textarea name='anteckning' style='width: 550px; height: 350px;'>").text(this.textContent);
});
$('.show_edit_button_'+id).show();
});
编辑完笔记后,我想将其上传到数据库。但是我不知道如何在文本区域中获取编辑过的文本?我尝试过.text,但当我使用它时,它被声明为未定义
有谁能帮我吗?试试这个:
$('input#mybutton').click(function() {
var text = $('textarea#mytextarea').val();
//send to server and process response
});
来源:在替换div内容之前,您应该先获取数据,然后再放入textarea,创建textarea后,您可以将之前存储的数据放入变量中。$…val。与php无关。您没有保存数据,在写入数据后,您需要通过任何操作(如单击按钮或使用FocusChange)获取数据,但我不知道如何将数据保存在变量中?给您的textarea一个id,并使用它返回$'mytextarea'.val;