简体   繁体   中英

iframe and validate.js

I have iframe inside my page for save data in database.I use validate.js to validate a field inside a iframe.If I validate field outside a iframe means in same page its work.If i do same thing in iframe its doesn't work.I want to know validate.js doesn't work inside a iframe?
I try:

var v = $("#form1").validate({
                    ignore: ':hidden',
                    rules: {
                        txtTitle: { required: true },
                        txtPost: { required: true },
                        txtSummary: { required: true }
                    },
                    messages: {
                        txtTitle: "Please enter a Post Title",
                        txtPost: "Please enter a Post description",
                        txtSummary: "Please enter a Post Summary"
                    }
                });

And in button click I use like this.

 $("#btnPost").live("click", function() {
                    if (v.form()) {
                     alert("Success");
                    }
                    else {
                    alert("fail");
                        return false;
                    }
                });

note:txtTitle,txtPost,txtSummary,btnPost all are iframe controls. Thanks.

It's likely you're using iFrames on different domains. jQuery won't traverse the iFrame as it would be a violation of the browsers cross-site policies. You won't be able to touch the inner-DOM if this is the case.

A solution would be to bind is to DOM events, but without knowing your form code I won't be able to give you an exact solution to your problem. It'll probably be like this:

$("#form1").contents().onclick = function() { // validate here };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM