如果使用javascript选中复选框,如何重定向到特定的链接? [英] How to redirect to a particular link if checkbox is checked using javascript?

查看:129
本文介绍了如果使用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

这篇关于如果使用javascript选中复选框,如何重定向到特定的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆