0

我可以获得以下代码的帮助吗?

$(document).ready(function() {

    $('#searchform').submit(function() {

        var action = '';

        if($('.action_url').val() == 'l_catalog') {
            action = 'http://catalog.site.com/uhtbin/cgisirsi.exe/x/0/0/57/5';
            $("#s").attr('name','searchdata1');
        } else if ($('.action_url').val() == 'l_wordpress'){
            action = '<?php get_bloginfo('url') ?>';
            $("#s").attr('name','s');
        }

        $(this).attr('action', action);
        return true; // submit
    });

    $('.action_url').change();

});

我正在尝试使用此功能将表单的操作设置为图书馆目录搜索页面或 wordpress 搜索页面。目前,单选按钮将选择/取消选择,并且仅搜索目录而不搜索 wordpress。我最初在网上找到了选择表单的代码,但现在必须使用单选按钮。(有一些困难)。用于此的 PHP 是:

$search_form .= '<form id="searchform" name="searchform" method="get" action="' . get_bloginfo('url') .'/">';
$search_form .= "\n" . "\t" . "\t";
$search_form .= '<div>';
$search_form .= "\n" . "\t" . "\t". "\t";
$search_form .= '<input type="radio" name="search_where" id="catalog" class="action_url" value="l_catalog" /> <label for="catalog">Library Catalog</label> <input type="radio" name="search_where" id="wordpress" class="action_url" value="l_wordpress" /> <label for="wordpress">Library Website</label>'; // <option value=\"l_catalog\">Library Catalog</option> \n \t \t \t \t <option value=\"l_wordpress\">Library Website</option>";
$search_form .= "\n" . "\t" . "\t". "\t";
if (is_search()) {
        $search_form .= '<input id="s" name="searchdata1" type="text" value="' . esc_html(stripslashes($_GET['s'])) .'" size="' . $search_form_length . '" tabindex="1" />';
} else {
        $value = __('To search, type and hit enter', 'thematic');
        $value = apply_filters('search_field_value',$value);
        $search_form .= '<input id="s" name="searchdata1" type="text" value="' . $value . '" onfocus="if (this.value == \'' . $value . '\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'' . $value . '\';}" size="'. $search_form_length .'" tabindex="1" />';
}
$search_form .= "\n" . "\t" . "\t". "\t";

$search_form .= '<input name="srchfield1" type="hidden" value="GENERAL^SUBJECT^GENERAL^^words or phrase">';
$search_form .= '<input name="sort_by" type="hidden" value="-PBYR">';
$search_form .= '<input name="user_id" type="hidden" value="WSC">';
$search_form .= '<input name="password" type="hidden" value="">';

$search_form .= "\n" . "\t" . "\t". "\t";

$search_submit = '<input id="searchsubmit" name="searchsubmit" type="submit" value="' . __('Search', 'thematic') . '" tabindex="2" />';

$search_form .= apply_filters('thematic_search_submit', $search_submit);

$search_form .= "\n" . "\t" . "\t";
$search_form .= '</div>';

$search_form .= "\n" . "\t";
$search_form .= '</form>';

我确定这很混乱,因为我不太了解 PHP 或 Javascript,而且我正在尝试在大联盟中打球。

4

1 回答 1

1

您的 JS 中的行:

action = '<?php get_bloginfo('url') ?>';

行不通。<?php ?>标记执行的服务器端。JS 代码在浏览器中执行。

您需要明确指定表单的操作 url: 类似于:

action = 'http://catalog.site.com/uhtbin/cgisirsi.exe/x/0/0/57/5';

我建议您创建一个隐藏字段:

$search_form .= '<input id="blog_url" type="hidden" value="' . get_bloginfo('url'). '">';

然后你的 JS 可以引用这个浏览器端:

action = $('#blog_url').val();

祝你好运!

于 2012-05-17T21:32:56.530 回答