V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
cuthead
V2EX  ›  JavaScript

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

  •  
  •   cuthead · 2015-03-06 17:01:03 +08:00 · 2453 次点击
    这是一个创建于 3330 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如在输入框输入v2ex,点按钮就能打开https://www.v2ex.com/
    6 条回复    2015-03-09 09:36:53 +08:00
    hpfs0
        1
    hpfs0  
       2015-03-06 17:04:58 +08:00
    这不是很easy吗?学过javascript的应该都会把
    cuthead
        2
    cuthead  
    OP
       2015-03-06 18:11:53 +08:00
    @hpfs0 我不会,教教我
    NewYear
        3
    NewYear  
       2015-03-06 18:11:58 +08:00
    <?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>
    RihcardLu
        4
    RihcardLu  
       2015-03-06 18:27:46 +08:00
    <script>
    var keyword = document.getElementById('keyword').value.trim();
    window.location.assign("http://www."+keyword+".com");
    </script>
    cuthead
        5
    cuthead  
    OP
       2015-03-06 19:01:52 +08:00
    @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  
       2015-03-09 09:36:53 +08:00
    这种问题去百度知道就行了。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5596 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 06:34 · PVG 14:34 · LAX 23:34 · JFK 02:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.