English 中文(简体)
1. 创建一门 j/j
原标题:Create a class with jQuery/javascript

In a page I create an instance of a class (MyClass), this class has 2 methods. But I d like to do 2 things :

  1. In (1), set the value this.message
  2. In (2), call the information method or another method of the class

感谢

<script type="text/javascript">
    $(document).ready(function () {
        var myClass = new MyClass("MyParam");
        $( #Target ).click(function (event) {
            myClass.save("Test");
        });
    }); 
</script>

function MyClass(myParam) {
    this.myParam = myParam;
    this.isError = false;
    this.message = "";
}

// Define the class methods.
MyClass.prototype = {
    save: function (action) {
        **(2)**
    },
    information: function (action) {
        **(1)**
    }
};

<>Update1>

在我执行以下编码时,< 编码> > > 数值载于<代码>。

MyClass.prototype = {

    click: function (action) {
        var myData;
        $.post(....., $("form").serialize(),
            function (data) {
                myData = data;
            });

        this.isError = this.information(myData);
    },

    information: function (data) {
        alert(data);
        return true;
    }

};
最佳回答

在<代码>save和>上/code>功能,this 应为目前的<代码>MyClass

因此,save,this.message应当有效,information,this.save(

最新资料:

click: function (action) {
    var myData;
    $.post(....., $("form").serialize(),
        function (data) {
            myData = data;
        });

    this.isError = this.information(myData);
}

是日本宇宙航空研究开发机构的一项请求,并且是同步的。 http://www.ohchr.org。 您需要在回击中打电话this.information

在电话中,this将不再是的标语,因此我们需要避免提及。 与此类似:

click: function (action) {
    var that = this;
    $.post(....., $("form").serialize(),
        function (data) {
            that.isError = that.information(data);
        });
}
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签