• <i id='bHIUQ'><tr id='bHIUQ'><dt id='bHIUQ'><q id='bHIUQ'><span id='bHIUQ'><b id='bHIUQ'><form id='bHIUQ'><ins id='bHIUQ'></ins><ul id='bHIUQ'></ul><sub id='bHIUQ'></sub></form><legend id='bHIUQ'></legend><bdo id='bHIUQ'><pre id='bHIUQ'><center id='bHIUQ'></center></pre></bdo></b><th id='bHIUQ'></th></span></q></dt></tr></i><div id='bHIUQ'><tfoot id='bHIUQ'></tfoot><dl id='bHIUQ'><fieldset id='bHIUQ'></fieldset></dl></div>
  • <small id='bHIUQ'></small><noframes id='bHIUQ'>

    <tfoot id='bHIUQ'></tfoot>

    <legend id='bHIUQ'><style id='bHIUQ'><dir id='bHIUQ'><q id='bHIUQ'></q></dir></style></legend>

        <bdo id='bHIUQ'></bdo><ul id='bHIUQ'></ul>

        附加 &lt;script src=&quot;&gt;&lt;/script&

        appending lt;script src=quot;quot;gt;lt;/scriptgt; to head based on screen width(附加 lt;script src=quot;gt;lt;/scriptgt;根据屏幕宽度显示头部)

        1. <i id='KpcXh'><tr id='KpcXh'><dt id='KpcXh'><q id='KpcXh'><span id='KpcXh'><b id='KpcXh'><form id='KpcXh'><ins id='KpcXh'></ins><ul id='KpcXh'></ul><sub id='KpcXh'></sub></form><legend id='KpcXh'></legend><bdo id='KpcXh'><pre id='KpcXh'><center id='KpcXh'></center></pre></bdo></b><th id='KpcXh'></th></span></q></dt></tr></i><div id='KpcXh'><tfoot id='KpcXh'></tfoot><dl id='KpcXh'><fieldset id='KpcXh'></fieldset></dl></div>

              <tbody id='KpcXh'></tbody>

            • <tfoot id='KpcXh'></tfoot>

              <small id='KpcXh'></small><noframes id='KpcXh'>

                <bdo id='KpcXh'></bdo><ul id='KpcXh'></ul>

                  <legend id='KpcXh'><style id='KpcXh'><dir id='KpcXh'><q id='KpcXh'></q></dir></style></legend>
                  本文介绍了附加 &lt;script src=&quot;&gt;&lt;/script&gt;根据屏幕宽度显示头部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要这样简单的东西:

                  i need something easy like this:

                  <script type="text/javascript">
                  <!--
                  
                  if (screen.width <= 699) {
                  document.location = "mobile.html";
                  }
                  //-->
                  </script>
                  

                  但不是重定向,我需要将 <script src="js.js"></script> 附加到 <head></头>

                  but instead of a redirect i'd need <script src="js.js"></script> to be appended in <head></head>

                  这可能吗?

                  推荐答案

                  实际操作:简短演示

                  你可以定义一个函数,像这样:

                  You can define a function, like this:

                  function appendScript(pathToScript) {
                      var head = document.getElementsByTagName("head")[0];
                      var js = document.createElement("script");
                      js.type = "text/javascript";
                      js.src = pathToScript;
                      head.appendChild(js);
                  }
                  

                  然后用适当的参数调用它(例如根据屏幕大小),像这样:

                  And then call it with the appropriate argument (e.g. according to screen size), like this:

                  appendScript("path/to/file.js");
                  

                  <小时>

                  如果您还需要从 head 中删除脚本(例如,基于其 'src' 属性),您可以定义一个函数,如下所示:


                  If you also need to remove a script from head (e.g. based on its 'src' attribute), you can define a function, like this:

                  function removeScript(pathToScript) {
                      var head = document.getElementsByTagName("head")[0];
                      var scripts = head.getElementsByTagName("script");
                      for (var i = 0; i < scripts.length; i++) {
                          var js = scripts[i];
                          if (js.src == pathToScript) {
                              head.removeChild(js);
                              break;
                          }
                      }
                  }
                  

                  然后用适当的参数调用它(例如根据屏幕大小),像这样:

                  And then call it with the appropriate argument (e.g. according to screen size), like this:

                  removeScript("path/to/file.js");
                  

                  <小时>

                  另外,请注意,使用 screen.width 返回用户屏幕的大小(不是浏览器窗口的宽度).


                  Also, note that using screen.width returns the size of the user's screen (not the browser-window's width).

                  如果您需要获取窗口大小,可以使用 $(window).width()(使用 jQuery).如果您想要无 jQuery"解决方案,请查看 this answer 用于跨浏览器的替代方案.

                  If you need to get the window size you can use $(window).width() (using jQuery). If you want a "jQuery-free" solution, take a look at this answer for cross-browser alternatives.

                  这篇关于附加 &lt;script src=&quot;&gt;&lt;/script&gt;根据屏幕宽度显示头部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

                  <legend id='JggWl'><style id='JggWl'><dir id='JggWl'><q id='JggWl'></q></dir></style></legend>
                      <tbody id='JggWl'></tbody>

                  1. <i id='JggWl'><tr id='JggWl'><dt id='JggWl'><q id='JggWl'><span id='JggWl'><b id='JggWl'><form id='JggWl'><ins id='JggWl'></ins><ul id='JggWl'></ul><sub id='JggWl'></sub></form><legend id='JggWl'></legend><bdo id='JggWl'><pre id='JggWl'><center id='JggWl'></center></pre></bdo></b><th id='JggWl'></th></span></q></dt></tr></i><div id='JggWl'><tfoot id='JggWl'></tfoot><dl id='JggWl'><fieldset id='JggWl'></fieldset></dl></div>
                    • <bdo id='JggWl'></bdo><ul id='JggWl'></ul>

                          1. <small id='JggWl'></small><noframes id='JggWl'>

                          2. <tfoot id='JggWl'></tfoot>