2013-10-06 32 views
0

朋友 在我的JSP中,我有以下的代碼格式以CSS代碼從一個JSP文件

<%@page isELIgnored="false" trimDirectiveWhitespaces="true" 
     contentType="text/html;charset=UTF-8"%> 
<%@ taglib prefix="bs" tagdir="/WEB-INF/tags"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 

<bs:main title="Status"> 
     <bs:content> 
       <bs:infoline /> 
       <div class="menubar"> 
         <bs:menu /> 


     </bs:content> 
</bs:main> 
<script type="text/javascript"> 
$(document).ready(function() { 
     $('.save,.close').hide(); 
}); 

$(document).ready(function() { 
      var seconds = 5000; // time in milliseconds 
      var reload = function() { 
        $.ajax({ 
          url: 'editStatus.jsp', 
        cache: false, 
        success: function(data) { 
          $('#refreshDIV').html(data); 
        } 
       }); 
      }; 
      setInterval(reload,seconds); 
     }); 
var textValue = ""; 
$('.pencil').on('click', function(){ 
    textValue = $(this).siblings('.textVal').text(); 
    $(this).siblings('.textVal').html("<input type='text' id='textVal' value='" + textValue + "' />"); 
    $(this).hide(); 
    $(this).siblings('.save, .close').show(); 
}); 

$('.save').on('click', function(){ 
    $(this).siblings('.textVal').html($(this).siblings('.textVal').find(':text').val()); 
    $(this).hide(); 
    $(this).siblings('.close').hide(); 
    $(this).siblings('.pencil').show(); 
}); 

$('.close').on('click', function(){ 
    $(this).siblings('.textVal').html(textValue) 
    $(this).hide(); 
    $(this).siblings('.save').hide(); 
    $(this).siblings('.pencil').show(); 
}); 
</script> 
<style type="text/css"> 
.textbox { 
     height: 24px; 
     width: 65px; 
     line-height: 22px; 
     padding: 3px 
} 

#textVal { 
     width: 22px; 
     margin-right: 4px 
} 

.icons { 
     float: left; 
     width: 20px; 
     height: 20px; 
} 

.save,.close { 
     display: none; 
     width: 20px; 
     height: 20px; 
     float: left 
} 

.textVal { 
     float: left; 
     width: 35px; 
     height: 20px; 
     margin-right: 5px 
} 

.pencil { 
     display: block 
} 

.red a { 
     color: red 
} 
</style> 

現在爲簡單起見,我想包括所有的代碼,在一個單獨的css文件開始,然後在上面的JSP中包含該css文件。 請建議最佳方式 謝謝

回答

1

將標記的內容移動到名爲「style.css」(或任何你喜歡的文件)的文件中。此標記添加到您的JSP:

<link rel="stylesheet" type="text/css" href="style.css" /> 
-1
Move the whole CSS code into a separate .css file and include that file into your php file. 

Code of Including CSS FILE: 

PHP 

<style> 
<?php include 'CSS/main.css'; ?> 
</style> 


HTML 
<link rel="stylesheet" href="http://www.mydomain.com/css/style.css"> 
+0

的問題沒有問關於PHP ...而且這是一個好主意,讓CSS文件作爲一個單獨的鏈接的文檔 - 這將減少的大小html文件,這可能需要經常下載,因爲可以獨立地緩存css。 – joews

相關問題