简体   繁体   English

如何将写入文本格式的信息翻译成javascript?

[英]How to translate information written into text form to javascript?

This is my attempt at my question 这是我对我的问题的尝试

I have a search box (HTML): 我有一个搜索框(HTML):

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

I then have php: 然后我有PHP:

$search =  $_POST["search"];

And then Jquery: 然后是Jquery:

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

But I can't seem to get the php into jQuery. 但我似乎无法将PHP变成jQuery。

var my_php_var = <?php echo json_encode($search) ?>
$(function(){
    var foundin = $('li:contains("<?php echo $search; ?>").css("color", "red");

Try changing it to : 尝试将其更改为:

$(function() {
    var foundin = $('li:contains(" <?php echo $search ?> ")').css( "color", "red" );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM