如何在 CI 中使用 JavaScript



我想编写CI的这个视图,如何编写js并在CI中调用它?这是代码:

<script type="text/javascript" src="<?php base_url() ?>/assets/js/jquery.js"></script>
<script type="text/javascript" src="<?php base_url() ?>/assets/js/qrcodelib.js"></script>
<script type="text/javascript" src="<?php base_url() ?>/assets/js/webcodecamjquery.js"></script>
<script type="text/javascript">
var arg = {
resultFunction: function(result) {
$('#as').append($("<input hidden='text' name='code' id='road' value='" + result.code + "'><br><label>QR Code Berhasil Discan, Silahkan Klik Allow / Berbagi data lokasi</label><br>"));
var x = document.getElementById("ar");
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else { 
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showPosition(position) {
x.innerHTML="<input hidden='text' name='lat' value='" + position.coords.latitude + 
"'><input hidden='text' name='long' value='" + position.coords.longitude + "'><label>Lokasi Telah didapatkan, silahkan Klik Submit</label>";
}
}
};
$("canvas").WebCodeCamJQuery(arg).data().plugin_WebCodeCamJQuery.play();            
</script>

您可以创建自定义 JS 文件,将 JS 代码添加到该文件中。 并在 CI 视图中包含新的 js 文件。

<script type="text/javascript" src="<?php base_url() ?>/assets/js/jquery.js"></script>
<script type="text/javascript" src="<?php base_url() ?>/assets/js/qrcodelib.js"></script>
<script type="text/javascript" src="<?php base_url() ?>/assets/js/webcodecamjquery.js"></script>
<script type="text/javascript" src="<?php base_url() ?>/assets/js/custJs.js"></script>

取新文件和名称为 custJs.js,并在 custJs .js 文件中添加以下代码

var arg = {
resultFunction: function(result) {
$('#as').append($("<input hidden='text' name='code' id='road' value='" + result.code + "'><br><label>QR Code Berhasil Discan, Silahkan Klik Allow / Berbagi data lokasi</label><br>"));
var x = document.getElementById("ar");
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else { 
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showPosition(position) {
x.innerHTML="<input hidden='text' name='lat' value='" + position.coords.latitude + 
"'><input hidden='text' name='long' value='" + position.coords.longitude + "'><label>Lokasi Telah didapatkan, silahkan Klik Submit</label>";
}
}
};
$("canvas").WebCodeCamJQuery(arg).data().plugin_WebCodeCamJQuery.play(); 

相关内容

  • 没有找到相关文章

最新更新