web2py中的sqlform提交按钮的id

时间:2013-12-24 12:28:10

标签: css web2py web2py-modules

我想在到达页面底部时添加一个java脚本来点击按钮...代码是

<script>
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

//taken from http://james.padolsey.com/javascript/get-document-height-cross-browser/
function getDocHeight() {
    var D = document;
    return Math.max(
        D.body.scrollHeight, D.documentElement.scrollHeight,
        D.body.offsetHeight, D.documentElement.offsetHeight,
        D.body.clientHeight, D.documentElement.clientHeight
    );
}

document.addEventListener("scroll", function (event) {
    if (getDocHeight() == getScrollXY()[1] + window.innerHeight) {
    document.getElementById('next').click()
     }
});
</script>

问题是该按钮是SQLFORM的提交按钮,所以我的问题是SQLFORM提交按钮的id是什么,或者我如何定义 ..我试过以下但是没有成功。

form2.custom.widget.submit_button['_id']='next'

它显示错误'NoneType'对象不支持项目分配。 关于Custom CSS classes for SQLFORM widget input in web2py有一些很好的信息,但我仍然无法弄明白......

1 个答案:

答案 0 :(得分:0)

您可以使用jQuery选择器标识提交按钮,例如"input[type=submit]"(或更具体地说,"#submit_record__row input[type=submit]")。如果要分配ID,可以执行以下操作:

form2.custom.submit['_id'] = 'next'

或:

form2.element('input[type=submit]')['_id'] = 'next'