English 中文(简体)
Script本模块模式中的预防过失
原标题:Overriding preventDefault() in the JavaScript module pattern

I m 采用单一吨位模式制造一种形式处理文字......

我不想把所有法典放在首位,而第一种方法却防止了过失:

//public methods
    handleSubmit: function (e) {

        //prevent the default submission process
        e.preventDefault();

},

防止失窃是劫持表格以阻止服务器边处理。

然后,我制定了验证规则......如果通过所有验证规则,则采用这种方法:

validData: function (error) {
        if (error.length === 0) {
            return true;
        } else {
            // If there are errors in the form then run alert message
            alert(error);
        }

    },

That being that if there are no errors then the server-side script processes the form and the item is added to the database (I m not using AJAX because I have an issue with images)

然而,返回真的没有在这里工作......我不知道为什么,但我相信,这样做的理由非常简单。

问题回答

can you skip the preventDefault function and just do something like this?

var hasErrors = false;
    if(myLogicHasErrors){
        hasErrors = true;
    }
    if(hasErrors) return false;

除非进行验证检查,否则将防止提交表格而不防止违约。





相关问题
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.

热门标签