javascript - framework 7 onclick event bind not working - Stack Overflow

I'm using framework7.io. I'm using their framework events and functioning but the onclick eve

I'm using framework7.io. I'm using their framework events and functioning but the onclick event is not bind with their page event pageInit.

I'm try to access form Data and convert it to json using formTOJSON as shown below.

JS part

//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

<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).

I'm using framework7.io. I'm using their framework events and functioning but the onclick event is not bind with their page event pageInit.

I'm try to access form Data and convert it to json using formTOJSON as shown below.

JS part

//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

<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).

Share asked Jun 20, 2016 at 6:02 Anurag JainAnurag Jain 4532 gold badges8 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Actually binding seems fine in your code.
Keep formToJSON code inside click event handle block try this:

$$(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. Hope this helps.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744879895a4598775.html

相关推荐

  • javascript - framework 7 onclick event bind not working - Stack Overflow

    I'm using framework7.io. I'm using their framework events and functioning but the onclick eve

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信