douxian1939 2017-10-21 15:39
浏览 48
已采纳

我是如何构建代码的http://fiddle.jshell.net/bwKZt/152/ - HTML和Javascript

I need build code such : http://fiddle.jshell.net/bwKZt/152/ but my code dosen't work ! I am a beginner. Please help me.

index.php:

<!DOCTYPE html><html>

    <head>
      <script>
        $("#label").bind("keyup", changed).bind("change", changed);
        function changed() {
          $("#url").val(this.value);
        }
      </script>
    </head>

    <body>
      <input type="text" id="label" />
      <input type="text" id="url" readonly />
    </body>

</html>
  • 写回答

2条回答 默认 最新

  • duanlaican1849 2017-10-21 15:43
    关注

    Some of the JavaScript here isn't native JavaScript , but is using a plugin called jQuery that makes searching and manipulating HTML elements easier.

    When you see $(), that's the jQuery way of finding elements. But it won't work because you don't have jQuery referenced at all.

    If you don't want to use jQuery, you can find elements with something like document.getElementById('label').

    But lots of people use jQuery to make referencing page elements short and sweet, as with $('#label').

    Try to reference jQuery first, like:

    <!DOCTYPE html><html>
    
        <head>
          <!-- The below line references an externally hosted copy of jQuery 2.2.4 -->
          <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    
          <script>
            // The below chunk is telling it to bind to the keyup event only AFTER the document has fully loaded.
            // Sometimes when your binding code is executed, the elements you wish to bind to aren't loaded yet. 
            $(document).ready(function(){
                $("#label").bind("keyup", changed).bind("change", changed);
            });
    
            function changed() {
              $("#url").val(this.value);
            }
          </script>
        </head>
    
        <body>
          <input type="text" id="label" />
          <input type="text" id="url" readonly />
        </body>
    
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型