简体   繁体   English

$ .mobile.changePage不加载CSS

[英]$.mobile.changePage doesn't load the CSS

This is a very weird situation with ajax. 对于ajax,这是一个非常奇怪的情况。 I have a login page which calls the mainpage via ajax, like this: 我有一个登录页面,该页面通过ajax调用主页,如下所示:

 // Function to call WCF  Service - Infrastructure       
    function CallService() {
        $.ajax({
            type: Type, //GET or POST or PUT or DELETE verb
            url: Url, // Location of the service
            data: Data, //Data sent to server
            contentType: ContentType, // content type sent to server
            dataType: DataType, //Expected data format from server
            processdata: ProcessData, //True or False
            success: function (msg) {//On Successfull service call
                ServiceSucceeded(msg);
            },
            error: ServiceFailed// When Service call fails
        });
    }

    function ServiceSucceeded(result) {

        if (DataType == "json") {
            var resultText = result;
            if (resultText.result == "True") {
                $.mobile.changePage("MainMenu.aspx",{ transition: "slideup" });
            }
            else {
                //Show Error Message
            }
        }
    }

In every page I have a reference to an js called "general.js" which contains the following code: 在每个页面中,我都有一个名为“ general.js”的js的引用,其中包含以下代码:

function processMenu(menuOptions) {
var options = menuOptions.split('');
var currentOptions = '1234567'.split('')

for (i = 0; i < currentOptions.length; i++) {
    var index = (i + 1) + '';
    if (options.indexOf(index) < 0) {
        var op = $('#op' + currentOptions[i]);
        op.attr('disabled', true);
        op.addClass('btndisabled');
        $(op).live("click", function (event) {
            //do stuff
            event.preventDefault(); // Prevent default link behaviour
        });
    }
}

} }

This code verifies some numbered controls and enable a CSS called "btndisabled" if it's requiered 此代码验证一些编号控件,并在需要时启用称为“ btndisabled”的CSS

The "btndisabled" CSS is: “ btndisabled” CSS为:

.btndisabled{    
    background-color: rgb(236,233,216);
    color: #CCC;
    font-style: normal;
}

Ok the situation is, when I use 好的,情况是,当我使用

$.mobile.changePage("MainMenu.aspx?",{ transition: "slideup" });

The Login.aspx content changes to the MainMenu.aspx content and the js: Login.aspx内容更改为MainMenu.aspx内容和js:

op.attr('disabled', true);
op.addClass('btndisabled');
$(op).live("click", function (event) {
    //do stuff
    event.preventDefault(); // Prevent default link behaviour
});

is executed, the CSS is not applied BUT the "event.preventDefault" is executed. 执行后,CSS不会应用,但执行“ event.preventDefault”。 I need to apply the CSS but I don't what is wrong. 我需要应用CSS,但我没有什么错。 Any ideas? 有任何想法吗?

UPDATE 更新

Watching the behaviour of the object on postback and in ajax call I realized something quite intersting, but I don't know what to think about it. 观察对象在回发和ajax调用中的行为,我意识到一些有趣的事情,但是我不知道该怎么考虑。

On Postback 回发时

在此处输入图片说明

Look at the HTMLAnchorElement 看一下HTMLAnchorElement

Ajax 阿贾克斯

在此处输入图片说明

If the DOM has not loaded the anchor object, HOW IS POSSIBLE TO ASSIGN THE event.preventDefault()??? 如果DOM尚未加载锚对象,则如何分配event.preventDefault()???

This is crazy... 这太疯狂了...

Your answer is probably on the jQuery Mobile forum itself: 您的答案可能在jQuery Mobile论坛本身上:

http://forum.jquery.com/topic/mobile-css-gets-lost-after-using-ajax-to-update-content http://forum.jquery.com/topic/mobile-css-gets-lost-after-using-ajax-to-update-content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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