0

我尝试了许多将我的应用程序用作 jquerymobile 的方法,但没有成功。我知道我必须使用 pageinit 而不是准备好文档。你能告诉我正确的方法吗?当我添加它时,它根本不起作用。这是代码

<head>
<link rel="stylesheet" href="https://s3.amazonaws.com/codiqa-cdn/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script>
    if (navigator.userAgent.match(/Android/i)) {
        window.scrollTo(0, 1);
    }
</script>
<script src="https://s3.amazonaws.com/codiqa-cdn/jquery-1.7.2.min.js"></script>
<script src="https://s3.amazonaws.com/codiqa-cdn/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
    try {
        $(function() {});
    } catch (error) {
        console.error("Your javascript has an error: " + error);
    }
</script>
<script>
    $(document).ready(function() {
        $("form").change(function() {
            $.post("test2.php",
            $("#myform").serialize());
        });
    });
</script>
</head>
<body>
    <div id="my-page" data-role="page">
        <form name="myform" id="myform" method="get">
            <label for="DogalGaz">Doğal Gaz</label>
            <select name="DogalGaz" id="DogalGaz" data-theme="" data-role="slider">
                <option value="">Seçiniz</option>
                <option value="off">Off</option>
                <option value="on">On</option>
            </select>
        </form>
    </div>

我所做的是,只需将表单数据发送到 test2.php 文件并进行处理。感谢您的任何帮助

4

1 回答 1

0

Flip Toggle Switch应该有 2 个选项而不是 3 个。

尝试这个:

<!DOCTYPE html>
<head>
<link rel="stylesheet" href="https://s3.amazonaws.com/codiqa-cdn/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script>
    if (navigator.userAgent.match(/Android/i)) {
        window.scrollTo(0, 1);
    }
</script>
<script src="https://s3.amazonaws.com/codiqa-cdn/jquery-1.7.2.min.js"></script>
<script src="https://s3.amazonaws.com/codiqa-cdn/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
    $(document).on('pageinit', function() {
        $("#myform").change(function() { // use #myform instead of form to only serialize one form.
            $.post("test2.php",
              $("#myform").serialize());
        });
    });
</script>
</head>
<body>
    <div id="my-page" data-role="page">
        <!-- include action and method in case javascript handler fails -->
        <form name="myform" id="myform" action="test2.php" method="post"> 
            <label for="DogalGaz">Doğal Gaz. Seçiniz: </label>
            <select name="DogalGaz" id="DogalGaz" data-theme="" data-role="slider">
                <option value="off">Off</option>
                <option value="on">On</option>
            </select>
        </form>
    </div>
</body>
</html>

每次切换切换时,这都会发布到 test2.php。

于 2013-04-25T07:19:53.240 回答