如果使用javascript选中复选框,如何重定向到特定的链接?

问题描述:

如果使用javascript选中复选框,如何重定向到特定链接?

How to redirect to a particular link if checkbox is checked using javascript?

我正在这样做,但不能为我工作。

I am doing this but its not working for me..

<input type="checkbox" name="yousendit" id="yousendit" value="1" onselect="return yousendit();"/>

<script type=javascript>
function yousendit()
{
        if(document.getElementById('yousendit').checked== "checked")
        {
            window.location='https://www.yousendit.com/dropbox?dropbox=mydomain';
            return false;
        }
        return true;

}
</script>

请帮助

您的来源有一些问题。这是工作版本:

There are some problems with your source. Here is the working version:

<input type="checkbox" name="yousendit" id="yousendit" value="1" onclick="return yousendit();"/>
<script>
function yousendit(){
    if(document.getElementById('yousendit').checked){
        window.location='https://www.yousendit.com/dropbox?dropbox=mydomain';
        return false;
    }
    return true;

}
</script>

更改:


  • onclick 而不是 onselect

  • 复选框 checked 属性为布尔

  • onclick instead of onselect
  • checkboxes' checked property is boolean