0

我正在此页面中运行优化测试: https ://www.thelotter.com/pt/bilhetes-loteria/africa-sul-powerball/?player=0

这是当前用于测试的 javascript:

/* Don't touch this code */
function waitForDelayedContent(selector, experiment, timeout, keepAlive) {
    var intervalTime = 50;
    var timeout = timeout || 3000;
    var keepAlive = keepAlive || false;
    var maxAttempts = timeout / intervalTime;
    var attempts = 0;
    var elementsCount = 0;
    var interval = setInterval(function() {
        if ($(selector).length > elementsCount) {
            if (!keepAlive) {
                clearInterval(interval);
            }
            experiment();
            elementsCount = $(selector).length;
        } else  if (attempts > maxAttempts) {
            clearInterval(interval);
        }
        attempts ++;
    }, intervalTime);
}
/* --------------------------------------------- */

waitForDelayedContent(".jackpot", function(){

$("#ctl00_tdMainRightSite").css({"display":"none", "visibility":""});
$("#divMainLeftSite").addClass("Clean_content_left_wide");
$("#tdMainLeftSite").addClass("Clean_TdMainLeftSite");
 
$(".play-request-options").css({"display":"none", "visibility":""});
  $(".play-request-options").attr("style", "display: none !important;");
$(".play-request-summary").addClass("Clean_play-request-summary");
$(".btn-lucky-numbers").css({"display":"none", "visibility":""});
$(".bonus-box").addClass("Clean_bonus-box");
$(".ticket-line-holder").attr("style", "width: 153px !important;");
$(".cell-value").attr("style", "height: 20px !important; width:22px !important; font-size:14px; padding-top: 3px; margin-right:1px;");

$(".SkipThisFixedPosition").css({"display":"none", "visibility":""});
$(".nav-tabs-simple").css({"display":"none", "visibility":""});
$(".wrapper").addClass("Clean_ticket-lines-container");
$(".long_regular_separator").addClass("Clean_long_regular_separator");
$(".nav-tab > .syndication").css({"display":"none", "visibility":""});
$(".nav-tab >  .bundle").css({"display":"none", "visibility":""});
$(".nav-tab >  .personal").css({"display":"none", "visibility":""});
$(".play-view-regular").addClass("Clean_play-view-regular");
$(".ticket-line-content").addClass("Clean_ticket-line-content");


$(".watermark").addClass("Clean_watermark");
$(".lottery-card").addClass("Clean_lottery-card");
$(".jackpot").addClass("Clean_jackpot");
$(".btn-size-large").addClass("Clean_btn-size-large");


$(".btn-size-large > .btn-content > .btn-text").addClass("Clean_btn-text");

$(".nav-buttons-group > .btn-color-blue").addClass("Clean_btn-color-blue");  
$(".nav-buttons-group > .btn-color-blue > .btn-content").addClass("Clean_btn-color-blue_content"); 
$(".play-type-selection-wrapper").addClass("Clean_play-type-selection-wrapper"); 
 
});

但是,我需要使用一个函数来运行测试,而不是 waitForDelayedContent 函数,该函数将在用户单击下面的任何 li 标记后运行测试(已经是 HTML 的一部分):

<div id="App-PlayRequest" data-ng-controller="PlayRequest.PlayRequestController" class="ng-scope">
<ul class="play-type-containers">
<li class="play-type-container" ng-click="setGameType(0)">...</li>
<li class="play-type-container" ng-click="setGameType(3)">...</li>
<li class="play-type-container" ng-click="setGameType(4)">...</li>
</ul>
</div>

用户单击任何 ng-click 后如何调用函数?

我认为这可能是一个简单的代码,但我不是开发人员,无法使答案中的代码起作用。

太感谢了!

4

3 回答 3

0

试试下面的代码片段:如果你想使用 Angular js,它会工作。

angular.module('app',[])
.controller('TodoListController', function ($scope) {
$scope.setGameType = setGameType;
 function setGameType(index) {
    console.log(index);
  }
});
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app='app'>
    <div ng-controller="TodoListController as todoList">
    <ul class="play-type-containers">
            <li class="play-type-container" ng-click="setGameType(0);">a...</li>
            <li class="play-type-container" ng-click="setGameType(3);">b...</li>
            <li class="play-type-container" ng-click="setGameType(4);">c...</li>
            </ul>
    </div>
    </div>

更新 此外,如果您只想使用 javscript:请尝试以下操作:-

function setGameType(index) {
  console.log(index);
}
    <ul class="play-type-containers">
            <li class="play-type-container" onclick="setGameType(0);">a...</li>
            <li class="play-type-container" onclick="setGameType(3);">b...</li>
            <li class="play-type-container" onclick="setGameType(4);">c...</li>
            </ul>

于 2017-05-10T09:35:08.987 回答
0

请试试这个。

<!DOCTYPE html>
<html>
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<body ng-app="myApp">

<div ng-controller="myCtrl">

<button ng-click="setGameType(1)">OK</button>
<ul class="play-type-containers">
<li class="play-type-container" ng-click="setGameType(0)">One</li>
<li class="play-type-container"   ng-click="setGameType(1)">Two</li>
<li class="play-type-container" ng-click="setGameType(2)">Three</li>
</ul>

</div>

<script>
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.count = 0;

$scope.setGameType = function(val) {
  alert("Do something here with id "+val);
};
}]);
</script>
</body>
</html>
于 2017-05-10T09:44:18.237 回答
0
<!DOCTYPE html>
<html>
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<body ng-app="myApp">

<div ng-controller="myCtrl">

<button ng-click="setGameType(1)">OK</button>
<ul class="play-type-containers">
<li class="play-type-container" ng-click="setGameType(0)">One</li>
<li class="play-type-container"   ng-click="setGameType(1)">Two</li>
<li class="play-type-container" ng-click="setGameType(2)">Three</li>
</ul>

</div>

//This script code according to john pappa's guideline.
<script>
(function() {
  angular.module('myApp')
    .controller('myCtrl', myCtrl);

  function myCtrl(
    $scope
    ) {
    $scope.setGameType = setGameType;
    function setGameType(val){
           console.log('Selected game type value',val);
           //do stuff which you want when user click.
    }
})();

</script>
</body>
</html>
于 2017-05-10T12:01:08.760 回答