我使用下面的代码进行简单的搜索,它在index.php中效果很好,但是因为我在header.html中添加了代码以包含在所有页面中,并且代码结果仅在index.php中起作用。
https://stackoverflow.com/a/34131517/5227465
index.php?text = keyword =好的otherpage.php?text = keyword =此处不起作用,因为仅在index.php中进行搜索处理]
我认为此元素中的问题意味着包含代码的当前页面:(document.getElementById)
<form id = "your_form" onsubmit="yourFunction()">
<input type="text" name="keywords">
<input type="submit" value="Search">
</form>
function yourFunction(){
var action_src = "http://localhost/test/" + document.getElementsByName("keywords")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}
有帮助吗?
我没有测试它,但是尝试这个:
function yourFunction(){
var action_src = "http://localhost/test/<?php echo basename(__FILE__, ''); ?>" + document.getElementsByName("keywords")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}