0

大家好,我是新手,我正在尝试创建一个搜索表单,但我的函数 php 文件似乎有问题。事实上,我知道问题出在我的“if”语句中,但我不知道是否有任何其他选项可以用来使其工作。这是代码:

function my_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value ==  . 'search & hit enter' . ) { this.value =  . '' . ; }" onblur="if(this.value ==  . '' . ) {this.value =  . 'search & hit enter' . ; }" />
<input type="hidden" value="post" name="post_type" id="post_type" />
</form>';

return $form;

}

add_filter( 'get_search_form', 'my_search_form' );
4

1 回答 1

0
search & hit enter

这部分是无效代码,需要转义

function my_search_form( $form ) {
    $form = '
    <form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
        <input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value == \'search &amp; hit enter\') { this.value = \'\'; }" onblur="if(this.value == \'\') {this.value =\'search &amp; hit enter\'; }" />
        <input type="hidden" value="post" name="post_type" id="post_type" />
    </form>';

    return $form;
}
于 2013-09-25T15:10:04.950 回答