jQuery 변수를 bootbox.js 확인 상자에 전달할 수 있습니까?어떻게하면 Bootbox에 변수를 전달할 수 있습니까?
"제품 이름은"변수처럼bootbox.confirm({
message: 'Are you sure you want to remove [productName]?',
callback: function(result) {
console.log(result);
},
title: "You can also add a title",
});
가 :
var productName = $('#product_name').val();
이 가능 뭔가가 여기에
코드인가?업데이트 : 아래 답변에 감사드립니다!
$('#product_name1 a.trash').click(function(event){
event.stopImmediatePropagation();
event.preventDefault();
var foo = $(this).parent().attr('id'); // #product_name1
alert(foo); // correct!
bootbox.confirm({
message: 'Are you sure you want to remove [productName]?',
callback: function(result) {
if (confirmed)
alert(foo); // undefined!
}
}
});
});
가 어떻게 "이"콜백 내에서 다시 정의 할
: 나는 이런 식으로 뭔가가 있다면....이 질문에 태킹? "foo"는 bootbox를 참조하기 때문에 undefined를 반환합니다.
내 실례로 좋았습니다. 고맙습니다! – LBF
$ (this)를 사용하면 같은 메소드가 콜백 내에서 작동하지 않는 이유를 알고 있습니까? $ (this)는 이제 bootbox를 대신 가리 키기 때문에 정의되지 않은 것 같습니다. 콜백 내에서 "this"를 재정의하는 방법이 있습니까? – LBF
외부 참조 콜백에 참조를 저장하고 해당 참조를 사용해야합니다. –