-2

我在 Jquery 中有一个变量,我在单击按钮时为其赋值。现在成功执行代码后,我想让变量为空。

$("#btnAdd").click(function () {

var myDataVariable= {};

myDataVariable.dataOne="SomeData";
myDataVariable.dataTwo="SomeData";
myDataVariable.dataThree="SomeData";
   //Pass the value to Database
                $.ajax({
                 success: function (data) {
                   //If Successfully Inserted Data I want to make "myDataVariable" Null 
                 } 
               });
});
4

2 回答 2

4
$("#btnAdd").click(function () {

var myDataVariable = {};

myDataVariable.dataOne="SomeData";
myDataVariable.dataTwo="SomeData";
myDataVariable.dataThree="SomeData";
   //Pass the value to Database
                $.ajax({
                 success: function (data) {
                   myDataVariable = null;
                   // you can use myDataVariable.attribute = null; if you want an attribute of this object to be null
                 } 
               });
});
于 2021-08-03T07:36:58.093 回答
2

您可以通过应用直接将其设置为 null myDataVariable = null; 但我认为没有必要,因为它会自动重置 next click 。

于 2021-08-03T07:40:50.947 回答