在 KeyUp 函数上使用 jquery 传递 space 的问题
issue passing space with jquery On KeyUp function
我有以下代码。我想要做的是在输入框中键入姓名时,从我的数据库中创建一个匹配联系人的下拉列表。我在键入时捕获输入变量并将其传递给 php 文件,该文件对其进行处理并将其加载到结果 div.
我成功了。但是,当我想在它们之间键入带有 space 的名称时,我无法将 space 作为值传递。当我这样做时,它不起作用。
例如:我输入 'John' ...列出所有与 John 相似的名字。但是当我键入 'John Smith' 时,由于单词之间的 space,所以没有任何列表。
所以问题很明显了。如何使 space 也通过。这样 'John Smith' 结果就显示出来了。我想我可能必须将它作为 %20 传递。但我试过的是下面。它不起作用。我在脚本中使用 'getcont()' 函数传递输入值。那就是我被困的地方。我确信这是一个简单的 jquery 解决方案。但我是 Jquery 的业余爱好者。请指教
<style>
#contdiv{display:none}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" async> </script>
<script>
$('document').ready(function(){
$('#contdiv').on('click', '.pno', function(){
var value = $(this).html();
var input = $('#cit');
input.val(value);
$('#contdiv').fadeOut('fast');
});
});
function getcont(){
var x = document.getElementById("cit");
if(x==" "){x="%20";}
$('#contdiv').fadeIn('fast').load('searchconts.php?cit='+x.value);
}
</script>
<div class="admininner">
<h3>Search Contacts on Phone</h3>
<input type="text" name="phone" id="cit" class="contdiv" onkeyup="getcont()" placeholder="Type to search">
<p id="contdiv"></p>
</div>
function getcont(){
var x = document.getElementById("cit").value;
if(x==" "){x="%20";}
$('#contdiv').fadeIn('fast').load('searchconts.php?cit='+x);
}
function getcont(){
var x = document.getElementById("cit");
x=encodeURI(x.value);
$('#contdiv').fadeIn('fast').load('searchconts.php?cit='+x);
}
我有以下代码。我想要做的是在输入框中键入姓名时,从我的数据库中创建一个匹配联系人的下拉列表。我在键入时捕获输入变量并将其传递给 php 文件,该文件对其进行处理并将其加载到结果 div.
我成功了。但是,当我想在它们之间键入带有 space 的名称时,我无法将 space 作为值传递。当我这样做时,它不起作用。
例如:我输入 'John' ...列出所有与 John 相似的名字。但是当我键入 'John Smith' 时,由于单词之间的 space,所以没有任何列表。
所以问题很明显了。如何使 space 也通过。这样 'John Smith' 结果就显示出来了。我想我可能必须将它作为 %20 传递。但我试过的是下面。它不起作用。我在脚本中使用 'getcont()' 函数传递输入值。那就是我被困的地方。我确信这是一个简单的 jquery 解决方案。但我是 Jquery 的业余爱好者。请指教
<style>
#contdiv{display:none}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" async> </script>
<script>
$('document').ready(function(){
$('#contdiv').on('click', '.pno', function(){
var value = $(this).html();
var input = $('#cit');
input.val(value);
$('#contdiv').fadeOut('fast');
});
});
function getcont(){
var x = document.getElementById("cit");
if(x==" "){x="%20";}
$('#contdiv').fadeIn('fast').load('searchconts.php?cit='+x.value);
}
</script>
<div class="admininner">
<h3>Search Contacts on Phone</h3>
<input type="text" name="phone" id="cit" class="contdiv" onkeyup="getcont()" placeholder="Type to search">
<p id="contdiv"></p>
</div>
function getcont(){
var x = document.getElementById("cit").value;
if(x==" "){x="%20";}
$('#contdiv').fadeIn('fast').load('searchconts.php?cit='+x);
}
function getcont(){
var x = document.getElementById("cit");
x=encodeURI(x.value);
$('#contdiv').fadeIn('fast').load('searchconts.php?cit='+x);
}