這是來自我自己的js文件。如何用自己的函數改變對象的屬性?
function hesap (hesapdiv, hesapmodal, hesapid){
this.hesapid = hesapid;
this.hesapdiv = hesapdiv;
this.hesapmodal = hesapmodal;
hesapdiv.on("click", "button", function() {
hesapmodal.modal("show");
});
hesapmodal.on("click", "button[hesapid]", function() {
var hesapid = $(this).attr('hesapid');
console.log(this.hesapid + "-" + hesapid + "-" + $(this).attr('hesapid'));
var isim = $(this).attr('isim');
hesapdiv.find("input").val(hesapid + " - " + isim);
hesapmodal.modal('hide');
});}
而下面的代碼,我可以在我的所有網頁中使用。
var hesap1 = new hesap($("#hesapdiv"), $("#HesaplarModal"), 36);
$("#kasaislemikaydet").on('click', function(event) {
event.preventDefault(); // To prevent following the link (optional)
alert(hesap1.hesapid);)};
現在,當用戶從模態中選擇'hesap'時,函數成功獲取屬性的值。但它不會將值分配給對象的'hesapid'。所以從網頁我不能得到hesapid的新價值。例如,點擊一個按鈕來獲得新選擇的'hesapid'的值,總是會提醒第一個值'36'。
謝謝,它有我一天 – fuatkaraca