1

这是我对我的问题的尝试

我有一个搜索框(HTML):

<form method="post">
    Search:<input type="text" name="search">
    <input value="Search" type="submit">
</form>

然后我有php:

$search =  $_POST["search"];

然后是 Jquery:

$(function() {
    var foundin = $('li:contains("    /* I want this part to be the bit entered by the form... $search */   ")').css( "color", "red" );
});

但我似乎无法将 php 放入 jQuery 中。

4

3 回答 3

1
var my_php_var = <?php echo json_encode($search) ?>
于 2013-10-09T11:01:40.283 回答
1
$(function(){
    var foundin = $('li:contains("<?php echo $search; ?>").css("color", "red");
于 2013-10-09T11:02:01.557 回答
1

尝试将其更改为:

$(function() {
    var foundin = $('li:contains(" <?php echo $search ?> ")').css( "color", "red" );
});
于 2013-10-09T11:02:18.470 回答