如果选中复选框,则按“特技”按钮继续下一页

时间:2015-07-17 03:01:48

标签: javascript jquery html

我怎么做这个是Javascript?如果选中复选框,我正试图在Javascript中找出一种方法来触发下面的提交按钮。这是什么。

<input type="checkbox" name="product[6]" value="1" checked="checked">

<input type="submit" value="Continue">

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

为了简单和特殊,我们将复选框ID添加到元素

<input id="product6" type="checkbox" name="product[6]" value="1" checked="checked">    
<input id="submit-btn" type="submit" value="Continue">

jQuery的:

$(function(){

    if( $('#product6').is(':checked') ){
        $('#submit-btn').click();
        // or submit the form
        $('#product6').closest('form').submit();
    }

});

答案 1 :(得分:1)

<强>已更新

您可以处理starts_with <- function(vars, match, ignore.case = TRUE) { if (ignore.case) match <- tolower(match) n <- nchar(match) if (ignore.case) vars <- tolower(vars) substr(vars, 1, n) == match } ends_with <- function(vars, match, ignore.case = TRUE) { if (ignore.case) match <- tolower(match) n <- nchar(match) if (ignore.case) vars <- tolower(vars) length <- nchar(vars) substr(vars, pmax(1, length - n + 1), length) == match } 事件并添加类似下面的条件:

JS:

submit()

答案 2 :(得分:1)

首先,您要为复选框输入一个id(例如checkbox-id) 并提交输入(例如submit-id)

document.getElementById("checkbox-id").onclick = myFunction;

function myFunction()
{
    document.getElementById("submit-id").click();
    //Or
    document.getElementById("submit-id").submit();
}