我一直在尝试使用 DNN(我已经使用了两周)向网站添加 JavaScript。我目前使用的版本是 07.04.00 (353)。我尝试将脚本粘贴到“页面设置”->“高级设置”中的标题和“模块设置”->“高级设置”中的标题中,但它似乎不起作用。我在下面发布了我想使用的脚本之一。
<script>
var radiobtnType = "ensidig";
var radiobtnOrient = "S";
var radiobtnHeatCap = "100";
//var tsvfilepath = data/ensidig_S_100.tsv
$(".btnType").click(function () {
radiobtnType = $(this).data('id');
update_box();
//var idPaaDenButtonDerBlevTrykketPaa = $(this).text() + $(this).data('id')
//alert(idPaaDenButtonDerBlevTrykketPaa);
});
$(".btnOrientation").click(function () {
radiobtnOrient = $(this).data('id');
update_box();
});
$(".btnHC").click(function () {
radiobtnHeatCap = $(this).data('id');
update_box();
});
function update_box() {
document.getElementById("foo2").value = "data/" + radiobtnType + "_" + radiobtnOrient + "_" + radiobtnHeatCap + ".tsv";
document.getElementById("pwd").value = "data/" + radiobtnType + "_" + radiobtnOrient + "_" + radiobtnHeatCap + ".tsv";
}
</script>
最佳答案
编辑:
如果您使用 DNN 4.9.1 或更高版本,则包含 jquery ( http://www.dnnsoftware.com/community-blog/cid/135141/dotnetnuke-tips-and-tricks-11-using-jquery-in-dotnetnuke )。这意味着您只需要添加文档就绪包装(或 $(function() { /* code goes here */ });
如 dnn 链接中建议的那样)。
--
首先确保您的页面包含 jQuery。如果没有,请包含它,例如通过使用 CDN:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
其次,将代码包装在 jQuery 的 read() 函数中(请参阅 https://learn.jquery.com/using-jquery-core/document-ready/ )。
<script>
$(document).ready(function() {
var radiobtnType = "ensidig";
var radiobtnOrient = "S";
var radiobtnHeatCap = "100";
//var tsvfilepath = data/ensidig_S_100.tsv
$(".btnType").click(function () {
radiobtnType = $(this).data('id');
update_box();
//var idPaaDenButtonDerBlevTrykketPaa = $(this).text() + $(this).data('id')
//alert(idPaaDenButtonDerBlevTrykketPaa);
});
$(".btnOrientation").click(function () {
radiobtnOrient = $(this).data('id');
update_box();
});
$(".btnHC").click(function () {
radiobtnHeatCap = $(this).data('id');
update_box();
});
function update_box() {
document.getElementById("foo2").value = "data/" + radiobtnType + "_" + radiobtnOrient + "_" + radiobtnHeatCap + ".tsv";
document.getElementById("pwd").value = "data/" + radiobtnType + "_" + radiobtnOrient + "_" + radiobtnHeatCap + ".tsv";
}
});
</script>
关于DNN 中的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451223/