2016-10-25 21 views
0

我只想在Coldfusion中檢查瀏覽器的移動時調用jquery函數,我可以做下面的調用。當我在移動瀏覽器上時,我沒有收到預期的結果。下面的電話甚至是正確的方式嗎?任何輸入讚賞。謝謝!jquery調用中的Coldfusion條件

<script> 
    $(document).ready(function(e) { 
     testfunction(); 
    }); 

    <cfif mobile> 
    function testfunction() { 
     /* function code here for mobile */ 
    } 
    </cfif> 

    <cfif not mobile> 
    function testfunction() { 
     /* different code for desktop function code here */ 
    } 
    </cfif> 
    </script> 
+1

這應該工作正常。你可能需要爲不同的功能命名。 –

+1

一步一個腳印。首先,只使用ColdFusion,確保將正確的值分配給移動變量。一旦你知道這是工作,缺乏預期的結果是一個JavaScript問題。 –

+0

是的,coldfusion Var設置正確,在桌面和移動設備上都檢查過,在JS中有問題。感謝您的投入! – user747291

回答

0

我試過這個,它工作正常。我們可以在腳本中添加一個ColdFusion條件。如果瀏覽器是移動瀏覽器,則調用第一個testfunction()。否則,調用第二個testfunction()。所以它絕對有效。也許你沒有通過代碼正確檢測到移動瀏覽器?也許這是你的問題的原因。

0

這是稍微簡單一些:

<script> 
    $(document).ready(function(e) { 
     testfunction(); 
    }); 

    <cfif mobile> 
    function testfunction() { 
     /* function code here for mobile */ 
    } 
    <cfelse> 
    function testfunction() { 
     /* different code for desktop function code here */ 
    } 
    </cfif> 
</script> 

但我覺得與具有屏幕上的兩個同名的功能有點怪。如果是我,我可能會去這個:

<script> 
    $(document).ready(function(e) { 
     testfunction(); 
    }); 

    function testfunction() { 
     <cfif mobile> 
      /* function code here for mobile */ 
     <cfelse> 
      /* different code for desktop function code here */ 
     </cfif> 
    } 
</script>