-5

我为下拉菜单添加了一个搜索框,由 javascript 函数解决。因为我用 php 显示表单和框,所以调用 javascript 函数“searchSel()”时遇到问题:

 echo "<input type=\"text\" id=\"realtxt\" onkeyup="searchSel()"><s";

错误:解析错误:语法错误,意外的 T_STRING,期待 ',' 或 ';'

onkeyup=". searchSel() ." 不工作

有任何想法吗?

4

4 回答 4

7

转义引号

echo "<input type=\"text\" id=\"realtxt\" onkeyup=\"searchSel()\">
                                                  ^            ^

你忘了逃跑onkeyup="searchSel()"


最好在外面使用单引号

echo '<input type="text" id="realtxt" onkeyup="searchSel()">'
     ^                                                      ^
于 2013-11-11T14:21:41.067 回答
1

尝试这个

 echo "<input type=\"text\" id=\"realtxt\" onkeyup=\"searchSel()\">
于 2013-11-11T14:22:26.423 回答
1

将字符串放在单引号中,以避免必须转义双引号:

echo '<input type="text" id="realtxt" onkeyup="searchSel()"><s';
于 2013-11-11T14:24:15.490 回答
1

你可能忘了逃避 searchSel()

echo "<input type=\"text\" id=\"realtxt\" onkeyup=\"searchSel()\">
于 2013-11-11T14:24:17.473 回答