我显示了一堆图像,我想编辑某个图像的细节。
我想通过突出显示来选择图像,然后单击edit
按钮。
它已经在工作但我想知道,当我第一次点击图像时,它不会被突出显示但是第二次会突出显示。 这是我的代码:
mainApp.controller('employeeController', ['$scope', '$http', function($scope, $http) {
$http.get(BASE_URL+'Employee/getAllEmployees').success( function(response) {
$scope.employees = response
});
$scope.setActive=function(empID){
$('img').click(function(){
$('.selected').removeClass('selected');
$(this).toggleClass('selected');
$('#edit_eq').prop('disabled',false)
});
}
}]);
这里是HTML部分:
<button id="edit_eq" type="button"
class="btn btn-default" disabled><i class="fa fa-edit"></i> Edit Employee
</button>
<div ng-controller="EmployeeController" class="row placeholders">
<div class="col-xs-6 col-sm-3 placeholder" ng-repeat="emp in employees | filter: name">
<img src="<?php echo base_url();?>{{emp.image}}" style="height:150px;width:150px" ng-click="setActive(this)">
<h4><a href="#viewEmp" data-toggle="modal">{{emp.lname}}, {{emp.fname}} {{emp.mname}}</a></h4>
<span class="text-muted">{{emp.position}}</span>
</div>
</div>
答案 0 :(得分:0)
您的setActive
功能click
会在您event
的每次点击时绑定新的<img />
<img />
。这样它只会在第二次点击时起作用,因为它第一次再绑定ng-click="setActive(this)"
。基本上这不是你想要完成的正确方法,因为你真正需要的唯一绑定是标记(ng-click
)中的绑定。
事实上,<img />
已经绑定了function
,并且在它执行的 $scope.setActive = function(empID) { //this get execute when <img /> gets clicked
$('.selected').removeClass('selected');
$(this).toggleClass('selected');
$('#edit_eq').prop('disabled',false)
};
中,你必须只指定你想要它做什么,而不是一次又一次地绑定它
做这样的事情:
# functionfile
function Show-MsgBox {
Write.Host "debugFUNC2"
#usage:
#Show-MsgBox -Prompt "This is the prompt" -Title "This Is The Title" -Icon Critical -BoxType YesNo -DefaultButton 1
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true)] [string]$Prompt,
[Parameter(Position=1, Mandatory=$false)] [string]$Title ="",
[Parameter(Position=2, Mandatory=$false)] [string]$Icon ="Information",
[Parameter(Position=3, Mandatory=$false)] [string]$BoxType ="OkOnly",
[Parameter(Position=4, Mandatory=$false)] [int]$DefaultButton = 1
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
switch ($Icon) {
"Question" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Question }
"Critical" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Critical}
"Exclamation" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Exclamation}
"Information" {$vb_icon = [microsoft.visualbasic.msgboxstyle]::Information}
}
switch ($BoxType) {
"OKOnly" {$vb_box = [microsoft.visualbasic.msgboxstyle]::OKOnly}
"OKCancel" {$vb_box = [microsoft.visualbasic.msgboxstyle]::OkCancel}
"AbortRetryIgnore" {$vb_box = [microsoft.visualbasic.msgboxstyle]::AbortRetryIgnore}
"YesNoCancel" {$vb_box = [microsoft.visualbasic.msgboxstyle]::YesNoCancel}
"YesNo" {$vb_box = [microsoft.visualbasic.msgboxstyle]::YesNo}
"RetryCancel" {$vb_box = [microsoft.visualbasic.msgboxstyle]::RetryCancel}
}
switch ($Defaultbutton) {
1 {$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton1}
2 {$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton2}
3 {$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton3}
}
$popuptype = $vb_icon -bor $vb_box -bor $vb_defaultbutton
$ans = [Microsoft.VisualBasic.Interaction]::MsgBox($prompt,$popuptype,$title)
return $ans
} #end function
function mafunc {
Write-Host "debugFUNC1"
$timer.start()
$timer
return 0
}
# calling file
$timer = New-Object System.Timers.Timer
#$timer.interval = 1800000
$timer.interval = 30000
$timer.Enabled = $true
$timer.AutoReset = $False
$scriptsleep = 0
$timer.stop()
$ThirtyAction = {
Write-Host "action"
Write-Host "action2"
if ((Show-MsgBox -Prompt "prompt" -Title "title" -Icon Critical -BoxType YesNo -DefaultButton 1) -eq "No") {
Write-Host "debugNO"
} else {
Write-Host "debugYES"
$timer
$timer.stop()
Show-MsgBox -Prompt "prompt" -Title "title" # standard promt = OKonly button
$timer.interval=30000
$timer.start()
$timer
Write-Host "timer start"
}
}
Register-ObjectEvent -InputObject $timer -EventName Elapsed -SourceIdentifier ThirtySecTimer -Action $ThirtyAction
myfunc