Salut, in .blade (Laravel) am un foreach cu niste produse, si un button ce apeleaza o functie JS. Totul functioneaza ok, doar ca acel buton functioneaza doar pentru primul obiect din array, pentru restul devine inexistent, nu mai apeleaza functia. Am pus un “console.log”, daca apas pe primul produs se afiseaza, daca apas pe al2-lea, nu mai merge.
Merci anticipat.
@extends('layouts.master')
@section('breadcrumb','Admin')
@section('content')
@foreach($inano as $i)
<div class="col-md-3 _2q{{ $i->ID }}">
<div class="ibox">
<div class="ibox-content product-box" style="margin-left:4px; background-color:#2121218f;">
<div class="product-desc">
ID Produs: <b>{{ $i->ID }}</b>
</br>
<button class="btn btn-xs btn-outline btn-primary" id="btnAlert"
tit="<center>{{ $i->Text }}</center>" sid="{{ $i->ID }}">
<i class="fa fa-eye" style="color:green;"></i> vezi descriere produs
</button>
</div>
</div>
</div>
</div>
@endforeach
@endsection
@section('js')
<script type="text/javascript">
function ezBSAlert(e){var a=$.Deferred(),s={type:"alert",modalSize:"modal-sm",okButtonText:"Set",cancelButtonText:"Cancel",yesButtonText:"Yes",noButtonText:"No",headerText:"Attention",messageText:"Message",alertType:"default",placeHold:"", inputFieldType:"text"};$.extend(s,e);return function(){var e="navbar-default";switch(s.alertType){case"primary":e="alert-primary";break;case"success":e="alert-success";break;case"info":e="alert-info";break;case"warning":e="alert-warning";break;case"danger":e="alert-danger"}$("BODY").append('<div id="ezAlerts" class="modal fade"><div class="modal-dialog" class="'+s.modalSize+'"><div class="modal-content"><div id="ezAlerts-header" class="modal-header '+e+'"><button id="close-button" type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><h4 id="ezAlerts-title" class="modal-title">Modal title</h4></div><div id="ezAlerts-body" class="modal-body"><div id="ezAlerts-message" ></div></div><div id="ezAlerts-footer" class="modal-footer"></div></div></div></div>'),$(".modal-header").css({padding:"15px 15px","-webkit-border-top-left-radius":"5px","-webkit-border-top-right-radius":"5px","-moz-border-radius-topleft":"5px","-moz-border-radius-topright":"5px","border-top-left-radius":"5px","border-top-right-radius":"5px"}),$("#ezAlerts-title").text(s.headerText),$("#ezAlerts-message").html(s.messageText);var t="";switch(s.type){case"confirm":var o='<button id="ezok-btn" class="btn btn-primary">'+s.yesButtonText+"</button>";s.noButtonText&&0<s.noButtonText.length&&(o+='<button id="ezclose-btn" class="btn btn-default">'+s.noButtonText+"</button>"),$("#ezAlerts-footer").html(o).on("click","button",function(e){"ezok-btn"===e.target.id?(t=!0,$("#ezAlerts").modal("hide")):"ezclose-btn"===e.target.id&&(t=!1,$("#ezAlerts").modal("hide"))});break;case"prompt":$("#ezAlerts-message").html(s.messageText+'<br /><br /><div class="form-group"><input placeholder="'+s.placeHold+'" type="'+s.inputFieldType+'" class="form-control" id="prompt" /></div>'),$("#ezAlerts-footer").html('<button class="btn btn-primary">'+s.okButtonText+"</button>").on("click",".btn",function(){t=$("#prompt").val(),$("#ezAlerts").modal("hide")})}$("#ezAlerts").modal({show:!1,backdrop:"static",keyboard:"false"}).on("hidden.bs.modal",function(e){$("#ezAlerts").remove(),a.resolve(t)}).on("shown.bs.modal",function(e){0<$("#prompt").length&&$("#prompt").focus()}).modal("show")}(),a.promise()}
$(document).ready(function()
{
$("#btnAlert").on("click", function()
{
console.log(1);
var prom = ezBSAlert({
messageText: $(this).attr('tit').replace(/(?:\r\n|\r|\n)/g, '<br>'),
headerText: "PRODUS - TEXT",
alertType: "warning"
});
});
});
</script>
@endsection