本帖最后由 kskkdjj 于 2011-04-26 09:37:33 编辑

解决方案 »

  1.   

    用js.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function() {
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i ++) {
    links[i].href = 'http://www.' + links[i].title;
    links[i].title = '';
    }
    }
    </script>
    </head><body>
    <a href="#" title="163.com">163.com</a><br />
    <a href="#" title="163.com">163.com</a><br />
    <a href="#" title="163.com">163.com</a><br />
    </body>
    </html>
      

  2.   

    我就想省去每个超连接的http://www.
    现在多了              ="#" title="
    还多一个字符出来了
      

  3.   

    <!--链接写成这样,不算头上的js代码,比原来多一个字符-_-! -->
    <a title="163.com">163.com</a>
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function() {
      var arr= document.getElementsByTagName('A');
      for (var i = 0;i<arr.length; i++){
        arr[i].href=arr[i].href.replace('http://www.','');
      }
    }
    </script>
    </head><body>
    <a href="http://www.163.com">aaaaa</a><br />
    <a href="http://www.163.com" >bbbbbbb</a><br />
    <a href="http://www.163.com" >ccccccccccc</a><br />
    </body>
    </html>
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <a h="163.com">163.com</a>
    </body>
    <script type="text/javascript">
    var links = document.getElementsByTagName('a');
        for (var i = 0; i < links.length; i ++) {
            links[i].href = 'http://www.' + links[i].h;
     }
    </script>
    </html>
    问下.. 缩成上面那样有副作用的吗?
    还有整个网站改成这样,对网站性能方面有影响吗?
    如果有影响在哪方面呢?
      

  6.   

    自定义一个h属性的话,用完以后删除,这样就能通过w3验证,应该没什么影响的。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function() {
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i ++) {
    links[i].href = 'http://www.' + links[i].getAttribute('h');
    links[i].removeAttribute('h');
    }
    }
    </script>
    </head><body>
    <a h="163.com">163.com</a><br />
    <a h="163.com">163.com</a><br />
    <a h="163.com">163.com</a><br />
    </body>
    </html>
      

  7.   

    兼容了,在问个题外的问题。
    一个页面用了getElementsByTagName和getElementsByTagID超过10个对性能有影响吗?
    还有javascript对象的属性可以用变量声明吗?
    比如
    var a=getElementsByTagName,b=length
      

  8.   

    links[i].removeAttribute('h');
    看明白了..
      

  9.   

    坦白的说,你的需求本身就是一种资源浪费,呵呵。直接写上http://www.有什么不好吗?
      

  10.   

    我以前写网页的习惯是能少用JS就不多写JS代码;能用CSS替代JS的就替代;只要效率方面没有打的差别,能直接写HTML代码的也不用JS。像你这样的需求,要是我就直接写死在网页上。
      

  11.   

    关于w3验证我弄错了,removeAttribute('h')删除a元素的h属性后,验证依然会报出一个警告。
      

  12.   

    所谓客户资源是什么?我理解应该以客户体验作为最重要的标准之一。比如说,我对一个不断跳出要我加入收藏夹的网站就反感至极。还有那些搞虚假链接的网站,大大的一个下载按钮,点进去什么都不是不说,搞不好还被它一火车的JS搞停,呵呵。当然,我不是说不能用JS写网页,恰恰相反,应该用,但要用的其所,不能乱搞。我13楼说的是这个意思。至于写死到网页就是用HTML把文件流直接输出到窗口,没必要使用JS的就不用。类似你的这个需求就是。你这个帖子的内容围绕的都是客户端内容,对服务器没影响,而且只是多用一点点JS问题不大。但积少成多、这里多点,那里多点,可能就是另一个样子了。我只是说我的观点而已,一家之言,不足为凭。呵呵
      

  13.   

    所谓客户资源是什么?
    客户宽带资源(页面体积过大)造成页面打开速度受影响。
    客户硬件资源(CPU,内存)JS使用不当对硬件造成影响。还有个楼上的问题能不能帮忙解决...
    还有javascript对象的属性可以用变量声明吗?
    比如var a=getElementsByTagName,b=length
    我想用a , b 代替属性 然后减少JS的体积....
    但是我实验没通过不知道有没办法?
      

  14.   

    变量这个问题,需要自定义个函数来实现,比如:
    function a(t) {
        var obj = document.getElementsByTagName(t);
        return obj;
    }
    var a = a('a');
    var b = a.length;
      

  15.   

    兄弟,凡事不能走极端。你不能无限制的缩小JS体积。它只是节省了一点加载文件时间。你说的我想用a , b 代替属性想都别想,那是标准属性。如果你不想用就自定义属性好了,但设置与读出同样也麻烦啊。呵呵
    你可以在JS写好后找个混淆器搞搞,压一下体积。关于文件体积的问题,我举个极端的例子:
    曾经试过一句CSS,写到页面里,用IE6打开,IE6立即崩溃。就一句话,体积小吧,但是......。
    所以,这是个综合平衡逻辑问题,看每个人怎么对待吧。
      

  16.   

    混淆器刚听说,看了下百科介绍,同时看介绍写的是关于JAVA的,不知html,CSS,JS支不支持呢?
    还有在哪下载呢?还是搜索关键字不够充分?
      

  17.   

    有好的HTML适用版本的介绍个给我呀。
      

  18.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--************************************************************************-->
    <!--* JavaScript Crunchinator Demo                                         *-->
    <!--*                                                                      *-->
    <!--* Copyright 2001 by Mike Hall                                          *-->
    <!--* Please see http://www.brainjar.com for terms of use.                 *-->
    <!--************************************************************************-->
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>BrainJar.com: JavaScript Crunchinator Demo</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link href="/common/default.css" rel="stylesheet" type="text/css" />
    <style type="text/css">/* Superfluous stylings for the form. */input, textarea {
      background-color: #d0f0f0;
      border-color: #00d0d0;
      border-width: 2px;
      padding: 2px;
      scrollbar-base-color: #00d0d0;
    }input.button {
      background-color: #00d0d0;
      border-color: #00d0d0;
      font-family: Arial, Helvetica, sans-serif;
      font-size: 10pt;
      font-weight: bold;
      padding: 0px;
      width: 5em;
    }table {
      border-color: #00f0f0 #009090 #009090 #00f0f0;
      border-style: solid;
      border-width: 2px;
      background-color: #00c0c0;
      padding: 4px;
    }td, th {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 10pt;
    }th {
      background-color: #008080;
      border-color: #000000;
      border-style: solid;
      border-width: 1px;
      color: #ffffff;
      padding-left: 8px;
      padding-right: 8px;
      text-align: left;
      width: auto;
    }</style>
    <script type="text/javascript">//<![CDATA[//*****************************************************************************
    // Do not remove this notice.
    //
    // Copyright 2001 by Mike Hall.
    // See http://www.brainjar.com for terms of use.
    //*****************************************************************************var literalStrings;  // For temporary storage of literal strings.function crunch(f) {  var input, output;
      var i;  // Get input script code, process it and display output.  f.elements.codeOut.value = "";
      f.elements.statusMsg.value = "Working...";
      input = f.elements.codeIn.value;
      output = input;
      f.elements.statusMsg.value = "Replacing literal strings...";
      output = replaceLiteralStrings(output);
      f.elements.statusMsg.value = "Removing comments...";
      output = removeComments(output);
      f.elements.statusMsg.value = "Compressing white space...";
      output = compressWhiteSpace(output);
      f.elements.statusMsg.value = "Combining literal strings...";
      output = combineLiteralStrings(output);
      f.elements.statusMsg.value = "Restoring literal strings...";
      output = restoreLiteralStrings(output);
      f.elements.statusMsg.value = "Done.";
      f.elements.codeOut.value = output;  // Compute sizes.  f.elements.sizeIn.value   = input.length;
      f.elements.sizeOut.value  = output.length;
      f.elements.sizeDiff.value = input.length - output.length;
      if (input.length > 0)
        f.elements.pctOut.value = 100 -
          Math.round(output.length / input.length * 10000) / 100;  return false;
    }function replaceLiteralStrings(s) {  var i, c, t, lines, escaped, quoteChar, inQuote, literal;  literalStrings = new Array();
      t = "";  // Split script into individual lines.  lines = s.split("\n");
      for (i = 0; i < lines.length; i++) {    j = 0;
        inQuote = false;
        while (j <= lines[i].length) {
          c = lines[i].charAt(j);      // If not already in a string, look for the start of one.      if (!inQuote) {
            if (c == '"' || c == "'") {
              inQuote = true;
              escaped = false;
              quoteChar = c;
              literal = c;
            }
           else
             t += c;
          }      // Already in a string, look for end and copy characters.      else {
            if (c == quoteChar && !escaped) {
              inQuote = false;
              literal += quoteChar;
              t += "__" + literalStrings.length + "__";
              literalStrings[literalStrings.length] = literal;
            }
            else if (c == "\\" && !escaped)
              escaped = true;
            else
              escaped = false;
            literal += c;
          }
          j++;
        }
        t += "\n";
      }  return t;
    }function removeComments(s) {  var lines, i, t;  // Remove '//' comments from each line.  lines = s.split("\n");
      t = "";
      for (i = 0; i < lines.length; i++)
        t += lines[i].replace(/([^\x2f]*)\x2f\x2f.*$/, "$1");  // Replace newline characters with spaces.  t = t.replace(/(.*)\n(.*)/g, "$1 $2");  // Remove '/* ... */' comments.  lines = t.split("*/");
      t = "";
      for (i = 0; i < lines.length; i++)
        t += lines[i].replace(/(.*)\x2f\x2a(.*)$/g, "$1 ");  return t;
    }function compressWhiteSpace(s) {  // Condense white space.  s = s.replace(/\s+/g, " ");
      s = s.replace(/^\s(.*)/, "$1");
      s = s.replace(/(.*)\s$/, "$1");  // Remove uneccessary white space around operators, braces and parentices.  s = s.replace(/\s([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])/g, "$1");
      s = s.replace(/([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])\s/g, "$1");
      return s;
    }function combineLiteralStrings(s) {  var i;  s = s.replace(/"\+"/g, "");
      s = s.replace(/'\+'/g, "");  return s;
    }function restoreLiteralStrings(s) {  var i;  for (i = 0; i < literalStrings.length; i++)
        s = s.replace(new RegExp("__" + i + "__"), literalStrings[i]);  return s;
    }//]]></script>
    </head>
    <body><div id="demoBox"><h3>JavaScript Crunchinator Demo</h3><p>You can condense JavaScript code using the form below. Just cut and paste
    any script code into the text area ed 'Input', press the 'Crunch' button
    and the condensed version will appear under 'Output.'</p><p>You can then use the 'Select' button to quickly highlight the output for
    easy cut and paste into a new source file.</p><p>Use your browser's <code>View Source</code> option to see the full source
    code.</p></div><p></p><form action="" onsubmit="return crunch(this)"><table border="0">
    <tr>
      <th colspan="3">Input</th>
    </tr>
    <tr>
      <td colspan="3"><textarea name="codeIn" rows="10" cols="80"></textarea></td>
    </tr>
    <tr>
      <td><b>Bytes:</b>  <input name="sizeIn"    type="text" size="10" disabled="disabled" /></td>
      <td><b>Status:</b> <input name="statusMsg" type="text" size="30" disabled="disabled" /></td>
      <td style="text-align:right;"><input class="button" type="submit" value="Crunch" /> <input class="button" type="reset" value="Clear" /></td>
    </tr>
    </table><p></p><table border="0">
    <tr>
      <th colspan="4">Output</th>
    </tr>
    <tr>
      <td colspan="4"><textarea name="codeOut" rows="10" cols="80"></textarea></td>
    </tr>
    <tr>
      <td><b>Bytes:</b>   <input name="sizeOut"  type="text" size="10" disabled="disabled" /></td>
      <td><b>Saved:</b>   <input name="sizeDiff" type="text" size="10" disabled="disabled" /></td>
      <td><b>% Saved:</b> <input name="pctOut"   type="text" size="10" disabled="disabled" /></td>
      <td style="text-align:right;"><input class="button" type="button" value="Select" onclick="this.form.codeOut.select();this.form.codeOut.focus();" /></td>
    </tr>
    </table></form></body>
    </html>
      

  19.   

    这个只是简单去掉空格和换行,用了下站长站的混淆器,代码变成x67\x65\x74\x45\x6c\x65\x6d
    实际文本显示文件体积反而增大了一倍,不知道真实效果是不是也这样?