如何在Visualforce标记中导入文件?我尝试使用URLFOR函数在Salesforce中引用静态资源。
以下脚本有效
<apex:page>
<html>
<body>
<h1>My First JavaScript</h1>
<p>Click Date to display current day, date, and time.</p>
<button type="button" onclick="myFunction()">Date</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = Date();
}
</script>
</body>
</html>
</apex:page>
但是,我想通过引用VisualForce中的函数来实现以下功能
<apex:page>
<html>
<body>
<h1>My First JavaScript</h1>
<p>Click Date to display current day, date, and time.</p>
<button type="button" onclick="myFunction()">Date</button>
<p id="demo"></p>
<apex:includeScript value="{!URLFOR($Resource.SalesDashboard, '/js/datefunction.js')}"/>
</body>
</html>
</apex:page>
我也尝试过:
<apex:page>
<html>
<body>
<h1>My First JavaScript</h1>
<p>Click Date to display current day, date, and time.</p>
<button type="button" onclick="myFunction()">Date</button>
<p id="demo"></p>
<apex:includeScript value="{!$Resource.SalesDashboard}"/>
</body>
</html>
</apex:page>
答案 0 :(得分:2)
在Visualforce页面中包含JavaScript的最佳方法是将JavaScript放在静态资源中,然后从那里调用它。例如,
<apex:includeScript value="{!$Resource.SalesDashboard}"/>