SharkIng
V2EX  ›  PHP

有没有什么办法让一个 Checkbox 的两次点击跳转不同的网站?

  •  
  •   SharkIng · Mar 12, 2015 · 2965 views
    This topic created in 4089 days ago, the information mentioned may be changed or developed.

    简单的说就是当不是checked的状态时候,Click之后会check然后调整一个网址,当时Checked状态的时候,Click会uncheck然后跳转的另外一个地址?

    我现在用的是以下的代码,没有使用JavaScript库

    <input type='checkbox' value=".htmlspecialchars('./WebsiteOne.php')." name='checket' onClick='if (this.checked) {window.location = this.value;}'></input>
    

    这个使用在当没有被选中时候选中它会跳转,然后相同道理我加了些想完成上面的描述的功能
    变成这个样子

    <input type='checkbox' value=".htmlspecialchars('./WebsiteOne.php')." values=".htmlspecialchars('./WebsiteTwo.php')." name='checket' onClick='if (this.checked) {window.location = this.value;}elseif {windows.location = this.values;}' ></input>
    

    求教~

    4 replies    2015-03-13 01:30:59 +08:00
    Septembers
        1
    Septembers  
       Mar 12, 2015   ❤️ 1
    <input type="checkbox" onclick="location.assign(this.checked?'<?=htmlspecialchars('./WebsiteOne.php')?>':'<?=htmlspecialchars('./WebsiteTwo.php')?>')"/>
    SharkIng
        2
    SharkIng  
    OP
       Mar 12, 2015
    @Septembers 谢谢
    cismous
        3
    cismous  
       Mar 12, 2015
    @Septembers
    @SharkIng
    这种应用场景应该是新窗口打开的吧?
    SharkIng
        4
    SharkIng  
    OP
       Mar 13, 2015
    @cismous 我们程序不是必须做到新窗口,所以没有这种设置,以上代码都是在当前窗口打开的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2855 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:51 · PVG 21:51 · LAX 06:51 · JFK 09:51
    ♥ Do have faith in what you're doing.