JavaScript是客戶端。 ColdFusion是服務器端。如果你想混合兩者,你需要Ajax。你應該嘗試更多的東西一樣使用jQuery,方便的Ajax:
// LOOK AT THE SCREEN WIDTH
if (screen.width <= 700) {
// LOAD THE PAGE INTO THE CORRECT SIZED DIV
$("#YourDiv").load("ColFusionFile-01.cfm");
} else {
// LOAD THE PAGE INTO THE CORRECT SIZED DIV
$("#YourDiv").load("ColFusionFile-02.cfm");
}
或者,您可能希望將用戶重定向:
// LOOK AT THE SCREEN WIDTH
if (screen.width <= 700) {
// SEND THE VISITOR TO THE CORRECT SIZED PAGE
window.location.href = "ColFusionFile-01.cfm"
} else {
// SEND THE VISITOR TO THE CORRECT SIZED PAGE
window.location.href = "ColFusionFile-02.cfm"
}
做file.cfm和file1.cfm包含HTML或JavaScript作爲他們的輸出內容? – 2012-03-06 05:14:14