简体   繁体   English

框架7 onclick事件绑定不起作用

[英]framework 7 onclick event bind not working

I'm using framework7.io . 我正在使用framework7.io I'm using their framework events and functioning but the onclick event is not bind with their page event pageInit . 我正在使用它们的框架事件并运行,但是onclick事件未与页面事件pageInit绑定。

I'm try to access form Data and convert it to json using formTOJSON as shown below. 我尝试访问form数据,并使用formTOJSON将其转换为json,如下所示。

JS part JS部分

//on page in it if page load via ajax 
$$(document).on('pageInit', function() {

    /*========query form=======*/

    var queryForm = app.formToJSON('#query-form');
    $$('#query-submit').on('click', function () {
       console.log(JSON.stringify(queryForm));
    });

});

HTML part HTML部分

<form id="query-form">
                    <div class="color-error" id="formErrorField" style="display: none;"></div>
                    <ul>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-input">
                                        <textarea name="question" placeholder="Type Here!"></textarea>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                    <br/>
                    <a href="#" class="button button-fill" id="query-submit">Submit</a>
                </form>

The same code is working for a different page load (non-ajax). 相同的代码适用于不同的页面加载(非ajax)。

Actually binding seems fine in your code. 实际上,在您的代码中绑定似乎不错。
Keep formToJSON code inside click event handle block try this: 将formToJSON代码保留在click事件句柄块中,请尝试以下操作:

$$(document).on('pageInit', function() {
    var queryForm = null;
    $$('#query-submit').on('click', function () {
     queryForm = app.formToJSON('#query-form');
       console.log(JSON.stringify(queryForm));
    });
});

Because when PageInit is happening your queryForm variable is empty according to your code.After filling the form you want to get value.So keep inside the click event handler. 因为发生PageInit时,根据您的代码,您的queryForm变量为空。填写表单后,您想获取价值。因此请保留在click事件处理程序中。 Hope this helps. 希望这可以帮助。

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

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