jQuery Mobile:如果inputbox为空,则加载对话框

时间:2012-05-31 19:05:06

标签: jquery jquery-mobile

我知道如何使用<a href="alert.html" data-rel="dialog">test</a>加载一个对话框我想要做的是如果任何表单值为空,则加载对话框。单击下一步(page15.html)链接时会触发/检查此项。有关如何实现这一目标的任何建议吗?

<a data-role="button" href="page15.html" data-icon="arrow-r" data-iconpos="right">
  Next
</a>
    <form action="#" method="POST">
        <div data-role="fieldcontain" class="no-field-separator">
            <fieldset data-role="controlgroup">
                <label for="textinput2">
                    <span class="c_404040 f_bold">Body Fat Measurements</span>
                </label>
                <input id="textinput2" placeholder="Subsc (mm)" value="" type="number" />
            <br />
                <label for="textinput3">
                </label>
                <input id="textinput3" placeholder="Supra Crest (mm)" value="" type="number" />
            <br />
                <label for="textinput4">
                </label>
                <input id="textinput4" placeholder="Bic (mm)" value="" type="number" />
            <br />
                <label for="textinput5">
                </label>
                <input id="textinput5" placeholder="Tri (mm)" value="" type="number" />
            </fieldset>
        </div>
    </form>

1 个答案:

答案 0 :(得分:0)

这样的事情会是一种方式:

var missingBox = 0;
$('a[href="page15.html"]').click(function(e) {
    e.preventDefault();
    $.each($('form input'),function() {
        if($(this).val() == 0) {
            missingBox += 1;
        } else {
        }
    });
        if(missingBox > 0) {
        console.log('alert');
    }
});