我可以获得以下代码的帮助吗?
$(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而且我正在尝试在大联盟中玩。
答案 0 :(得分: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();
祝你好运!