【问题标题】:how to place the document url in text input?如何将文档 url 放在文本输入中?
【发布时间】:2011-09-02 21:55:01
【问题描述】:

我不太确定应该如何获取顶部 URL,然后将其放入文本输入中?这是我想出的,但没有运气。谁有想法?另外,我怎样才能使这个文本输入不可编辑?

<script type="text/javascript">
    var topURL = document.URL; 
    function SelectAll(id)
    {
        document.getElementById(id).focus();
        document.getElementById(id).select();  
    }
</script>

<input type="text" id="txtfld" onClick="SelectAll('txtfld');" style="width:200px" value ="topURL" />

我也在value参数中尝试了value ="document.URL"value ="document.write(document.URL)"

【问题讨论】:

    标签: javascript html forms url


    【解决方案1】:
     <script type="text/javascript">
    var topURL = document.URL; 
        function SelectAll(id)
        {
            document.getElementById(id).focus();
            document.getElementById(id).select();
    
        }
        </script>
    
        <input type="text" id="txtfld" onClick="SelectAll('txtfld');" style="width:200px" value ="topURL" />
    <script language="javascript">
     document.getElementById('txtfld').value = topURL;
    </script>
    

    【讨论】:

      【解决方案2】:

      在脚本中试试这个:

      document.getElementById('txtfld').value = window.location.href;
      

      【讨论】:

      • 同意。删除内联 javascript。我敢肯定,您整天都在等待我的批准。
      【解决方案3】:

      window.location.href 会帮你拿的。

      【讨论】:

        【解决方案4】:

        应该很清楚。

         <script type="text/javascript">
        var topURL = document.URL; 
            function SelectAll(id)
            {
                var foo=document.getElementById(id) 
                foo.value=topURL
        
            }
            </script>
        
            <input type="text" id="txtfld" onClick="SelectAll('txtfld');"
        style="width:200px" value ="topURL" />
        

        【讨论】:

          【解决方案5】:

          我发现最简单的是

          <script type="text/javascript" language="JavaScript">
               document.write('<input type="text" name="pgUrl" value="' + document.URL + '">');
          </script>
          

          虽然很想知道如何摆脱 http:// :)

          【讨论】:

            猜你喜欢
            • 2011-03-10
            • 1970-01-01
            • 2014-04-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-05-10
            • 2020-10-26
            • 2021-12-06
            相关资源
            最近更新 更多