单击div时,它应显示在文本框中,并且应该可以在编辑按钮上编辑 什么应该是ajax代码 我用PHP完成了这个,但想用ajax做
<script>
function edit()
{
$.ajax({
});
}
</script>
<div id="edit1" name="edit1">edit1</div>
<div id="edit2" name="edit2">edit2</div>
<div id="edit3" name="edit3">edit3</div>
<input type="text" id="text"/>
<button onclick="edit(this.value)">Edit</button>
答案 0 :(得分:2)
<div>when clicked on the div it should be displayed on textbox
and it should be editable on edit button what should be the ajax code
i have done this with php but want to do this with ajax</div>
JS:
function divClicked() {
var divHtml = $(this).html();
var editableText = $("<textarea />");
editableText.val(divHtml);
$(this).replaceWith(editableText);
editableText.focus();
// setup the blur event for this new textarea
editableText.blur(editableTextBlurred);
}
function editableTextBlurred() {
var html = $(this).val();
var viewableText = $("<div>");
viewableText.html(html);
$(this).replaceWith(viewableText);
// setup the click event for this new div
viewableText.click(divClicked);
}
$(document).ready(function() {
$("div").click(divClicked);
});
答案 1 :(得分:1)
在下面的jquery中尝试获取文本框中的div值:
$('div').click(function(){
$('input').val($(this).text());
});
然后,您可以使用ajax调用更新文本框。