这是我的div可见的链接
<a href="javascript:addMethod()">+ Create a new comment</a>
和调用它的方法如下
function addMethod()
{
try {
var div = document.getElementById('addComments');
div.style.visibility = "visible";
var textArea = document.getElementById('Textarea1');
textArea.style.visibility = "visible";
var mashupId = _settings.ratedObjectId;
var tenantId = _settings.tenantId;
var comments = null;
var user = { "Id": 2007,
"FirstName": "Ufone",
"LastName": "",
"EmailAddress": "ahmed.ali@vidizmo.com509" };
var ratingInfo = {
"Id": 0,
"TenantId": tenantId,
"UserId": user.Id,
"FirstName": user.FirstName,
"LastName": user.LastName,
"Rating": 0,
"EmailAddress": user.EmailAddress,
"Comments": comments,
"RatedObjectTypeInfo": { "Id": 2 },
"RatingTypeInfo": { "Id": 1 },
"MashupRatingInfo": { "MashupMetaInfoId": mashupId },
"RatedObjectId": mashupId,
"TotalCount": 0
};
var url = "http://services.farooq.tv/RatingInfoManagementService/RatingInfoManagementService.svc/ajax/AddRating";
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(ratingInfo),
contentType: "application/json",
timeout: 5000,
success: function (d)
{
if (d.comments == true){
console.log(d);
alert("Success");
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
}
});
}
catch (err)
{
alert(err);
}
}
这是我的div,里面是文本区域和按钮
<div id="addComments" align="center" style="width:300px; height:300px; visibility:hidden">
<textarea id="Textarea1" style="width:300px; height:300px; visibility:hidden"> </textarea>
<button>Submit</button>
<button>Cancel</button>
</div>
我想在文本区域中添加文本,并在按下提交按钮后将其保存在变量中
<button>Submit</button>
和我想要存储文本区域文本的变量是
var comments = null;
请帮助我开始编程......
答案 0 :(得分:1)
以下是您的解决方案http://jsfiddle.net/yangchenyun/erANK/
您可以使用此行设置textArea
var comments = textArea.value = 'This is added text';