V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
cuthead

如何用 Javascript 写一个小程序,输入框输入一段文字点按钮就能打开一个网站(文字和网站已经预先配对好)?

  •  
  •   cuthead · Mar 6, 2015 · 3074 views
    This topic created in 4076 days ago, the information mentioned may be changed or developed.
    比如在输入框输入v2ex,点按钮就能打开https://www.v2ex.com/
    6 replies    2015-03-09 09:36:53 +08:00
    hpfs0
        1
    hpfs0  
       Mar 6, 2015
    这不是很easy吗?学过javascript的应该都会把
    cuthead
        2
    cuthead  
    OP
       Mar 6, 2015
    @hpfs0 我不会,教教我
    NewYear
        3
    NewYear  
       Mar 6, 2015
    <?php
    $php是最好的语言=1;
    if ( $php是最好的语言==1 && isset($_GET["site"]) && $_GET["site"] == "v2ex" ) header("Location: https://www.v2ex.com");
    ?>
    <form>
    <input name="site">
    <input type="submit">
    </form>
    kechx
        4
    kechx  
       Mar 6, 2015
    <script>
    var keyword = document.getElementById('keyword').value.trim();
    window.location.assign("http://www."+keyword+".com");
    </script>
    cuthead
        5
    cuthead  
    OP
       Mar 6, 2015
    @NewYear
    @RihcardLu 最好写成带按钮的,用Javascript。不光有v2ex网站,还希望有engadget之类的网站,还希望支持中文,比如输入瘾科技能打开cn.engadget.com

    <!DOCTYPE html>
    <html>
    <body>

    <button onclick="myFunction()">button</button>

    <script>
    function myFunction() {
    window.open("http://www.v2ex.com", "_self");
    }
    </script>

    </body>
    </html>
    b821025551b
        6
    b821025551b  
       Mar 9, 2015
    这种问题去百度知道就行了。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2661 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 02:56 · PVG 10:56 · LAX 19:56 · JFK 22:56
    ♥ Do have faith in what you're doing.