首页 > 解决方案 > 我如何在输入中写入空间并使用 jquery

问题描述

我已经搜索了表格并且这个工作很好但是当我写这样的空间时:''它不起作用并且我得到了这个错误:未捕获的错误:语法错误,无法识别的表达式:......我输入之前的脚本:

var table_length=10,table_key="",page=1;

我的输入是:

<input onKeyUp="
    table_key=this.value;
    reload_table();" type="search" class="form-control input-sm" placeholder="" aria-controls="datatable-responsive">

我的脚本是:

function reload_table(){
    $("#load_table").load("manage_table_engine.php?mode=tr&table=generator_tables&table_id=1&length=" + table_length + "&key=" + table_key + "&page=" + page);
}

以及此信息的帮助:当有人在输入中写一些东西然后键入键盘时,确实将 table_key var 更改为输入值,就像您在输入中看到的那样:onKeyUp="table_key=this.value; reload_table();"然后将一些 php 页面加载到表中,它正在工作并修复但是当我写空间它不工作,我不知道我能做什么,我做了一些像添加引号和双引号但不工作的事情。

我知道一件事,当我写东西并用任何单词成功更改 table_key var 但加载脚本不起作用并在控制台中发送错误时,此错误是完全错误:

Uncaught Error: Syntax error, unrecognized expression: &page=1
at Function.oe.error (jquery.min.js:2)
at oe.tokenize (jquery.min.js:2)
at Function.oe [as find] (jquery.min.js:2)
at w.fn.init.find (jquery.min.js:2)
at Object.<anonymous> (jquery.min.js:2)
at u (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)

我希望给你很好的信息请帮助我

和这个主题的错误相同:JQUERY: Uncaught Error: Syntax error, unrecognized expression 但我没有在这个主题中找到一些东西来帮助我自己

如果有人认为我不使用这个库,我会使用它:<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

标签: jqueryajaxformsinputonkeyup

解决方案


使用 encodeURI(uri) 对加载方法输入进行编码;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
    var table_length=10,table_key="",page=1;
    function reload_table(){
        $("#load_table").load(encodeURI("manage_table_engine.php?mode=tr&table=generator_tables&table_id=1&length=" + table_length + "&key=" + table_key + "&page=" + page));
    }
</script>
<input onKeyUp="table_key=this.value;reload_table();" type="search" class="form-control input-sm" placeholder="" aria-controls="datatable-responsive"/>

推荐阅读