添加母版页时Javascript无法正常工作 [英] Javascript not working when added masterpage
本文介绍了添加母版页时Javascript无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我要用J逗业自动完成文本框,用逗号分隔多个单词。我从这个博客获得了源代码
http://www.aspdotnet-suresh.com/2012/07/ jquery-autocomplete-textbox-with.html
但是当试图将母版页添加到此页面时,javascript无法正常工作或自动填充不出现。任何人都指出我的错误
hi all Im tring to do Jquery autocomplete textbox with multiple words separated by comma .I got source code from this blog
http://www.aspdotnet-suresh.com/2012/07/jquery-autocomplete-textbox-with.html
But when tried to add master page to this page javascript not working or autofill not appearing.can anyone point out my mistake
<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$("#txtSearch").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/GetAutoCompleteData",
data: "{'username':'" + extractLast(request.term) + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
},
focus: function () {
// prevent value inserted on focus
return false;
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
});
$("#txtSearch").bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active) {
event.preventDefault();
}
})
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
}
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="demo">
<div class="ui-widget">
<label for="tbAuto">Enter UserName: </label>
<%--<input type="text" id="txtSearch" />--%>
<asp:TextBox ID="txtSearch" runat="server" Width="300px">
</div>
</div>
谢谢和问候
Amrutha
thanks and regards
Amrutha
推荐答案
( document )。ready( function (){
SEARCHTEXT();
});
function SearchText(){
(document).ready(function () { SearchText(); }); function SearchText() {
( #txtSearch)。autocomplete({
source: function (request,response){
("#txtSearch").autocomplete({ source: function (request, response) {
.ajax({
type: POST,
contentType: application / json; charset = utf-8,
url: Default.aspx / GetAutoCompleteData,
data: {'username':' + extractLast(request.term)+ '},
dataType: json,
成功:功能(数据){
响应(data.d);
},
错误: function (结果){
alert( 错误);
}
});
},
焦点:功能(){
// 阻止在焦点上插入值
return false < /跨度>;
},
select: function (event,ui){
var terms = split( this .value);
// 删除当前输入
terms.pop();
// 添加所选项目
terms.push(ui.item。值);
// 添加占位符以获取末尾的逗号和空格
terms.push( );
this .value = terms.join( ,);
return false ;
}
});
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Default.aspx/GetAutoCompleteData", data: "{'username':'" + extractLast(request.term) + "'}", dataType: "json", success: function (data) { response(data.d); }, error: function (result) { alert("Error"); } }); }, focus: function () { // prevent value inserted on focus return false; }, select: function (event, ui) { var terms = split(this.value); // remove the current input terms.pop(); // add the selected item terms.push(ui.item.value); // add placeholder to get the comma-and-space at the end terms.push(""); this.value = terms.join(", "); return false; } });
这篇关于添加母版页时Javascript无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文