[英]Moving textfield value in dialog box using jquery
I am having a button and a text field and textarea.Now what i was trying to do is that on click of button move the values of textfield and textarea into a dialog box where both can be edited. 我有一个按钮以及一个文本字段和textarea.Now我现在想做的是单击按钮时将textfield和textarea的值移动到一个对话框中,可以对两者进行编辑。
So i wrote the following code for it : 所以我为此编写了以下代码:
In html : 在html中:
<div id="dialog"></div>
<input type="button" value="EDIT" id="editbutton" name="editbutton" class="editbutton" style="float: right;"></input>
<input type="text" value="mytextvalue" id="edittitle" name="edittitle" class="edittitle" style="visibilty: hidden;"></input>
<textarea value="mytextarea" id="editsubject" name="editsubject" class="editsubject" style="visibilty: hidden;"></input>
In jquery i did something like this : 在jQuery中,我做了这样的事情:
$('.editbutton').click(function ()
{
$("#dialog").dialog({
autoOpen: true,
modal: true,
title: "Edit Your Question",
width: 600,
height: 300,
resizable: false,
buttons: {
"Edit": function() {
$(this).dialog("close");
callback("1");
},
"Discard": function() {
$(this).dialog("close");
callback("2");
}
}
});
});
Javascript callback function : JavaScript回调函数:
function callback(value,RowId) {
if (value=="1") {
alert("edit");
}
else if(value=="2"){
alert("Rejected");
}
}
But my problem is to show the textfield and textarea in editable form in dialog box.Please help 但是我的问题是在对话框中以可编辑的形式显示文本字段和文本区域。请帮助
I modified the code in your last comment from: 我从以下位置修改了您最后一条评论中的代码:
var qtitle=$('#questiontitle').val();
var qtext=$('#questiontext').val();
$("#dialog").html("Title: <input id='myquestiontitle' type='text'><br><br>Question : <input id='myquestion' type='text'>");
to: 至:
var qtitle = $('#edittitle').val();
var qtext = $('#editsubject').val();
$("#dialog").html("Title: <input id='myquestiontitle' type='text' value='" + qtitle + "'><br><br>Question : <textarea id='myquestion'>" + qtext + "</textarea>");
This gets the values from the hidden input fields edittitle
and editsubject
and puts them into the editable input fields in the dialog. 这将从隐藏的输入字段edittitle
和editsubject
获取值,并将其放入对话框中的可编辑输入字段中。
Note how I've changed the second input field in the dialog to a textarea so it's consistent with the hidden input fields. 请注意我如何将对话框中的第二个输入字段更改为文本区域,以使其与隐藏的输入字段一致。
Create dialog outside the click events. 在点击事件之外创建对话框。 onclick just fire those callbacks. onclick只会触发这些回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.