我试着在我的asp.net application.But中使用多选下拉树插件和Jquery组合树,得到了一个错误"Custom.aspx:1694 Uncaught:$(...).comboTree is not a function“error?".I是个新手,如果有人能帮上忙,我将不胜感激。
我的.aspx页面中的代码
<script src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha384-
nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
crossorigin="anonymous">
</script>
<script src="comboTreePlugin.js"></script>
<script src="icontains.js"></script>
<script type="text/javascript">
var myData = [
{
id: 0,
title:'Item 1 '
},
{
id: 1,
title:'Item 2',
subs: [
{
id: 10,
title:'Item 2-1'
}, {
id: 11,
title:'Item 2-2'
}, {
id: 12,
title:'Item 2-3'
}]
},
];
$('#example').comboTree({
source : myData
});
</script>
<td width="270px" valign="top" align="center">
<asp:TextBox ID="example" runat="server" ></asp:TextBox>
</td>发布于 2020-07-22 06:47:29
在调用JQuery函数之前,您需要确保JQuery已经加载,这可以使用$(document).ready(function() { });来完成。
您还需要确保已经加载了组合树插件。然而,我在你的问题中看不到插件。此外,您可能需要添加静态ID (除非它是在web.config中设置的)。要将其添加到文本框中,请尝试执行以下操作:
<asp:TextBox ID="example" runat="server" ClientIDMode="Static"></asp:TextBox>无论如何,尝试添加以下内容:
var myData = [/* add array */ ]
$(document).ready(function() {
$('#example').comboTree({ source : myData });
});有关完整的工作示例:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous"></script>
<script src="comboTreePlugin.js"></script>
<script type="text/javascript">
var myData = [
{
id: 0,
title: 'Item 1 '
},
{
id: 1,
title: 'Item 2',
subs: [
{
id: 10,
title: 'Item 2-1'
}, {
id: 11,
title: 'Item 2-2'
}, {
id: 12,
title: 'Item 2-3'
}]
},
];
$(document).ready(function () {
$('#example').comboTree({
source: myData
});
});
</script>
</head>
<body>
<form runat="server">
<asp:TextBox ID="example" runat="server" ClientIDMode="Static"></asp:TextBox>
</form>
</body>
</html>https://stackoverflow.com/questions/63023216
复制相似问题