简体   繁体   English

服务器端的Onclick事件html按钮

[英]Onclick event html button on serverside

I have this project given to me the design of the project is on javaScript function the java script is call on the master page named Admin.Master.我给了我这个项目,该项目的设计是基于 javaScript 函数,java 脚本在名为 Admin.Master 的母版页上调用。 The javascript funtion for design is shared by two webform rewardPoints.aspx and Transactions.aspx用于设计的 javascript 功能由两个 webform RewardPoints.aspx 和 Transactions.aspx 共享

Now my question is how can i able to add on click event in btnExportExcel inside Transaction.aspx现在我的问题是如何在 Transaction.aspx 内的 btnExportExcel 中添加点击事件

my java script funtion :我的java脚本功能:

function TransSearchControls(page, cs) {
    var html = "";
    var display = (cs == "all") ? "inline-block" : "none";

    html += "<div class='col-xs-12 body'>";
    html += "<div class='col-xs-1 text-left' style='margin-top:5px'>Filter/s:</div>";
    html += "<div class='col-xs-6 col-sm-2'><input type='text' class='input-sm form-control trans-controls-txt-search' placeholder='Search Employee' /></div>";
    html += "<div class='col-xs-6 col-sm-2' style='display:" + display + "'><select class='input-sm slctSoaFilter form-control' >";
    html += "<option value='all' selected disabled>Select Transactions</option>";
    html += "<option value='all'>All</option>";
    html += "<option value='redeem'>Redeemed</option>";
    html += "<option value='earn'>Earned</option>";
    html += "</select></div>";
    html += "<div class='col-xs-1 text-right' style='margin-top:5px'>Date/s:</div>";
    html += "<div class='col-xs-5 col-sm-2'><input type='date' class='input-sm form-control dateFrom' /></div>";
    html += "<div class='col-xs-5 col-sm-2'><input type='date' class='input-sm form-control dateTo' /></div>";

    html += "<div class='col-xs-6 col-sm-2'><button class='btn btn-sm btn-primary btnSearchTrans form-control' type='button' page='" + page + "'><span class='glyphicon glyphicon-search'></span>&nbsp;&nbsp;Search</button></div>";
    html += "</div>";
    if (page == "Transactions") {
        html += "<div class='col-xs-12' style='margin-top:10px'>";
        html += "<button type='button' class='btn btn-sm btn-danger' id='btnExportExcel'><span class='glyphicon glyphicon glyphicon-import'></span>&nbsp;&nbsp;Export Excel</button>";
        html += "<span class='filename-container'></span>";
        html += "</div>";
    }
    if (page == "RewardPoints") {
        html += "<div class='col-xs-12' style='margin-top:10px'>";
        html += "<button type='button' class='btn btn-sm btn-primary' id='btnAddPoints'><span class='glyphicon glyphicon-plus-sign'></span>&nbsp;&nbsp;Add Points</button>&emsp;";
        html += "<button type='button' class='btn btn-sm btn-danger' id='btnImportExcel'><span class='glyphicon glyphicon glyphicon-import'></span>&nbsp;&nbsp;Import Excel</button>";
        html += "<span class='filename-container'></span>";
        html += "</div>";
    }

i want to add onclick event on the button inside我想在里面的按钮上添加 onclick 事件

if (page == "Transactions") 

this is how the function call in my Transaction.aspx这就是我的 Transaction.aspx 中的函数调用方式

<script>
        $(document).ready(function () {
            $(".menu-title").html('<span class="glyphicon glyphicon-transfer"></span>&nbsp;&nbsp;Transactions');
            $(".inner-menu-title").html('<span class="glyphicon glyphicon-sort-by-attributes-alt"></span>&nbsp;&nbsp;List of Employee Transactions');
            $(".transactions .main").addClass("active");

            TransSearchControls("Transactions", "all");
            var url = "&EmpName=&DateFrom=" + DefaultDate("from") + "&DateTo=" + DefaultDate("to");
            GetTransactions("Transactions", "all", url);


            $('.dateFrom').val(DefaultDate("from"));
            $('.dateTo').val(DefaultDate("to"));
        });
    </script>

I hope you understand what i mean i'm not good at English我希望你明白我的意思我不擅长英语

You need to add an onclick event to the html button element.您需要向 html 按钮元素添加一个onclick事件。 So it would look something like this:所以它看起来像这样:

html += "<button type='button' onclick='TransactionsEvent()' class='btn btn-sm btn-danger' id='btnExportExcel'><span class='glyphicon glyphicon glyphicon-import'></span>&nbsp;&nbsp;Export Excel</button>";

Then you must just update the function in the Javascript to match up:然后你必须只更新 Javascript 中的函数来匹配:

function TransactionsEvent() {
    //do something here
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM