多按钮功能

Multiple Button function

本文关键字:功能 按钮      更新时间:2023-09-26

我有 2 个主界面文件,分别是 Admin.aspx 和 Index.aspx。这 2 个文件连接到 1 个相同的文件,是 Seatbook.js。一个 JavaScript 文件,用于从界面操作交互中的数据。在admin.aspx和Index中.aspx有一个按钮"预订"了这个按钮,我想拥有多种功能。

当我从管理员运行时.aspx然后单击"预订"按钮,然后我将重定向到 ForAdmin.aspx 文件。如果我从索引运行.aspx那么我将重定向到 ForUser.aspx

我在 seatbook.js 文件上的方法上获取了重定向链接代码。 这是我下面的代码。

  <input type="button" name="submit" class="ui-state-default ui-corner-all" onclick="ShowArrData()" value="Book Seat" />

以上是我在管理员上的按钮代码.aspx任一索引.aspx

function ShowArrData() {
for (var i = 0; i < o.length; i++) {
    seatname = o[i].Name;
    console.log(seatname);
    time = jQuery('#timepicker_7').val();
    console.log(time);
    console.log("hallo");      
    var url = "ForAdmin.aspx?noSeat=" + encodeURIComponent(lObjSeat[0].Name) + "&endtime=" + encodeURIComponent(time);                
    window.location.replace(url);
    // alert(url);
} 

}

(让我们忘记循环代码。 没什么)上面的代码是我单击"预订"按钮时调用的方法

 var url = "ForAdmin.aspx?noSeat=" + encodeURIComponent(lObjSeat[0].Name) + "&endtime=" + encodeURIComponent(time);                
    window.location.replace(url);

这就是我重定向链接的方式。 带有 2 个参数。我想让它成为多个重定向,具体取决于您在哪里运行程序。

可能吗?

更新:

在第一个回答之后,我编辑了我的问题,以使其像我的问题一样清晰

在 showarrdata() 之前,当我单击"预订"按钮时,我将调用 book_tickes() 方法,然后它将显示对话框然后转到 showarrdata();

function book_tickets() {    
var tickets = jQuery('.seat.selected').length;    
if(tickets==0)
{
    alert('Please select at least one seat to continue...!');
    return false;    
}else
{
    x = jQuery('.seat.selected').toArray();
    jQuery('#seat-form-data').html('');
    jQuery('.seat.selected').each
    (
        function () {
            var ydata = jQuery(this).html();
            xdata = ydata.replace("[class]", "");
            jQuery('#seat-form-data').append(xdata);
        }
    );
    jQuery('#seat-form-data').append('<input type="submit" value="submit">');
    jQuery('#seat-form-data input[type="submit"]:first').trigger('click');       
   $("#dialog").dialog("open");       
}

}

那么这是对话框

$(function() {
$( "#dialog" ).dialog({
    autoOpen: false,
    width: 400,
    buttons: [
        {
            text: "Ok",                
            click: function () {                    
                ShowArrData(lObjSeat);
                $(this).dialog("close");                                       
            }
        },
        {
            text: "Cancel",
            click: function() {$( this ).dialog( "close" );}
        }
    ]
});    
$( "#dialog-link" ).click(function( event ) {
    $( "#dialog" ).dialog( "open" );
    event.preventDefault();
});

});

之后调用了 showarrdata() 方法。

因此,在转到showarrdata()(我的重定向链接代码)之前,需要一些步骤来处理我的数据。

通过简单的设置按钮的id,并在javascript函数"ShowArrData()"中检查相同的id,并基于此进行操作。

<input type="button" id="admin" name="submit" class="ui-state-default ui-corner-all" onclick="ShowArrData(this)" value="Book Seat" />

贾夫文

function ShowArrData(e) {
  if(e.attr('id')=="admin")
  {
     //code here for admin page
  }
  else
  {
     / code for index page
  }
}

问候苏尼尔·普拉巴卡尔 C