1

我正在尝试用一种主要语言制作多语言词典。我想使用单选按钮来更改语言(以及 php 中的查询) 我的想法是拥有例如 3 个单选按钮:-English、-German、-Spanish。那就是改变语言/查询。

现在我有这样一个代码(在 index.php 中):

<script type='text/javascript'>
$(function(){
    $("form#search-form").submit(function(){
        $("#results").fadeOut();
        $.ajax({
            type:"GET",
            data: $(this).serialize(),
            url: "search.php",
            success: function(msg)
                {
                $("#results").html(msg);
                $("#results").fadeIn();
                }
        });
    return false;
    });

});
</script>

那是 jquery 脚本,可以立即获得结果。以及 div 中的搜索表单:

<div id='container'>
<div id='search-box'>
    <form id='search-form'>
        <input type='text' id='input-text' name='s' value=''/>
    </form>
</div>

在 search.php 中:

$q = "SELECT * FROM lauk_pamed WHERE diakr LIKE '%".$search_term. "%'or mask LIKE '%" .$search_term. "%' ORDER BY words LIMIT 21";
$r = mysql_query($q);


     if(mysql_num_rows($r)==0)//no result found
    {
    echo "<div id='search-status'>Nothing was found</div>";
    }
 else //result found
    {
    echo "<ul>";
    while($row = mysql_fetch_assoc($r))
        {
        $prus = str_ireplace($search_term, "".$search_term."", $row['wirds']);
        $des = $row['descr'];
?>

所以我的想法是:如果 -English 打开,则查询必须是:

    $q = "SELECT * FROM lauk_pamed WHERE diakr LIKE '%".$search_term. "%'or english LIKE '%" .$search_term. "%' ORDER BY words LIMIT 21";

如果 -German 打开,则查询必须是:

    $q = "SELECT * FROM lauk_pamed WHERE diakr LIKE '%".$search_term. "%'or german LIKE '%" .$search_term. "%' ORDER BY words LIMIT 21";

等等。我怎么能使用单选按钮来做到这一点?

4

2 回答 2

2

HTML:

<input id="radioBtn" type="radio" name="radioButton" value="english">

JS:

$("#radioBtn").onChecked{

}
于 2012-05-10T15:38:28.927 回答
1

在您的 HTML 中执行以下操作:

<div id='search-box'>
    <form id='search-form'>
        Translate this:
        <input type='text' id='input-text' name='translate' value=''/>

        <br/><br/><br/>

        Into:<br/>
        <input type="radio" name="language" value="English"> English<br>
        <input type="radio" name="language" value="Spanish"> Spanish<br>
        <input type="radio" name="language" value="German" checked> German

        <br/><br/><br/>

        <button type="submit">Submit</button>
    </form>
</div>​​​​

然后在 PHP 中,您可以像这样获取字符串和语言:

<?php
    $search_string = $_GET['translate'];
    $language      = $_GET['language'];

    // Rest of your code...

如果您希望在单击其他语言时自动提交表单,您可以在 JS 中执行此操作:

$('input[name=language]').change(function() {
    $('#search-form').submit();
});
于 2012-05-10T15:37:40.497 回答