我使用下面编写的脚本进行自动完成。当我在我的母版页中添加jquery-1.8.3.js时它正在工作,但是当我从母版页中删除它并将其添加到特定页面时,它就会停止工作。我不知道为什么会导致这个问题。
<script type="text/javascript">
function pageLoad(sender, args) {
$(function () {
$(".tb").autocomplete({
source: function (request, response) {
$.ajax({
url: "AutoInsuranceCompanyList.asmx/FetchCompanyList",
data: "{ 'cmp': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item.INSCO
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1
});
});
}
</script>
<asp:UpdatePanel ID="UpdatePanel3" UpdateMode="Conditional" Visible="true" RenderMode="Inline"runat="server">
<ContentTemplate>
<ul class="formList">
<li class="clear">
<label>
Insurance Company:</label>
<asp:TextBox ID="txtInsuranceCompany" class="tb" runat="server" MaxLength="40"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator33" runat="server" ControlToValidate="txtInsuranceCompany" ErrorMessage="Please enter insurance company name" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
</li>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
在浏览器的运行时显示
<input id="ContentPlaceHolder1_txtInsuranceCompany" class="tb ac_input" type="text" autocomplete="off" maxlength="40" name="ctl00$ContentPlaceHolder1$txtInsuranceCompany">
请帮忙
答案 0 :(得分:0)
试试这个
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function () {
var availableTags = Array();
jQuery.ajax({
url: "AutoInsuranceCompanyList.asmx/FetchCompanyList",
data: "{ 'cmp': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
$.map(data.d, function (item) {
availableTags.push(item.INSCO);
})
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
jQuery(".tb").autocomplete({
source: availableTags
});
})
</script>
答案 1 :(得分:0)
当我在我的母版页中放置jquery-1.8.3.js并运行它时,它工作正常并在浏览器中显示
<input id="ContentPlaceHolder1_txtInsuranceCompany" class="tb ui-autocomplete-input" type="text" maxlength="40" name="ctl00$ContentPlaceHolder1$txtInsuranceCompany" autocomplete="off">
我不明白为什么在我将jquery-1.8.3.js放在aspx文件中时它无效,而在母版页中它正常工作
我将我的jquery放在aspx页面的内容部分,它起作用了。感谢您的努力和回复朋友。