我需要在此表中获取事件ID,当单击btnStopEvent时,它获取当前时间并将其显示在同一个表中,即Endtime列,例如我有5个事件ID 1,2,3,4 ,5当用户点击第2列中的按钮时,它应该在EndTime列中显示当前时间,这是我现在所拥有的
function GetStartUserData() {
var IPAddress = $('#IPAddress').text();
(IPAddress == '' ? null : 'ipaddress=' + IPAddress)
var EventId = '';
var Category = $('#categories').val();
var ExtraData = $('#txtcomment').val();
return {
MachineName: IPAddress
, EventId: EventId
, CategoryName: Category
, Comments: ExtraData
}
}
function DisplayStartData(downTimeStart) {
console.log(downTimeStart);
var newContent = '';
$.each(downTimeStart.data, function (i, item) {
newContent += Hesto.Html.StartTR(item.downTimeStart);
newContent += Hesto.Html.CreateTD('<input type="button" value="Stop" id="btnStopEvent">');
newContent += Hesto.Html.CreateTD(item.EventId);
newContent += Hesto.Html.CreateTD(item.CategoryName);
newContent += Hesto.Html.CreateTD(item.StartTime);
newContent += Hesto.Html.CreateTD(item.EndTime);
newContent += Hesto.Html.CreateTD(item.Comments);
newContent = Hesto.Html.EndTR(newContent);
});
$('#DowntimeList').append(newContent);
}
HTML:
<div id="panel"><table id="Downtimetable" class="hesto">
<thead>
<tr>
<th>END OF DOWNTIME</th>
<th>Event ID</th>
<th>CATEGORY NAME</th>
<th>START TIME</th>
<th>END TIME</th>
<th>COMMENTS</th>
</tr>
</thead>
<tbody id="DowntimeList">
</tbody>
<tfoot>
</tfoot>
</table></div>
<div class="label" id="IPAddress"><%Response.Write(Request.QueryString["ipaddress"]); %></div>
json page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Web.Script.Serialization;
using Hesto.SQL;
using Hesto;
public partial class services_json_DownTimeStartByMachineName : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Collections.Specialized.NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection();
nvc.AddFromQueryString(Request.QueryString);
nvc.AddFromQueryString("MachineName", Request.UserHostAddress, Request.QueryString);
nvc.AddFromQueryString("EventId", "NULL", Request.QueryString);
nvc.AddFromQueryString("CategoryName","NULL",Request.QueryString);
nvc.AddFromQueryString("StartTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),Request.QueryString);
nvc.AddFromQueryString("Comments", "NULL", Request.QueryString);
StoredProcedureCaller spc = new StoredProcedureCaller();
spc.Execute(Request.QueryString, Resources.StoredProcedureDefinitions.DownTimeStartTimeByMachineName, Resources.ConnectionStrings.HESTOTESTING);
Response.Write(spc.ToString("json"));
}
}
json page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Web.Script.Serialization;
using Hesto.SQL;
using Hesto;
public partial class services_json_DownTimeStop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Collections.Specialized.NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection();
nvc.AddFromQueryString(Request.QueryString);
nvc.AddFromQueryString("EventId","", Request.QueryString);
nvc.AddFromQueryString("EndTime", DateTime.Now.ToString(), Request.QueryString);
StoredProcedureCaller spc = new StoredProcedureCaller();
spc.Execute(nvc, Resources.StoredProcedureDefinitions.DownTimeStopEvent, Resources.ConnectionStrings.HESTOTESTING);
Response.Write(spc.ToString("json"));
}
}
答案 0 :(得分:1)
您可以使用onclick方法:
<button onclick="myFunction(eventID)">Click me</button>
然后你可以传递你的&#34;事件ID&#34;到JS部分:
function myFunction(eventID){
alert("Your Event ID : " + eventID);
}
或者您可以使用jquery:
$("button").click(function() {
alert(this.id); // or alert($(this).attr('id'));
});