selected() - WordPress 函数参考中文文档

返回介绍

selected()

发布于 2017-09-11 字数4837 浏览 772 评论 0

selected( mixed $selected,  mixed $current = true,  bool $echo = true )

Outputs the html selected attribute.


描述

Compares the first two arguments and if identical marks as selected


参数

$selected

(mixed)
(Required)
One of the values to compare

$current

(mixed)
(Optional)
(true) The other value to compare if not just true

Default value: true

$echo

(bool)
(Optional)
Whether to echo or just return the string

Default value: true


返回值

(string) html attribute or empty string


源代码

File: wp-includes/general-template.php

function selected( $selected, $current = true, $echo = true ) {
	return __checked_selected_helper( $selected, $current, $echo, 'selected' );
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

  • wp-includes/general-template.php:
    __checked_selected_helper()

Used By

  • wp-includes/customize/class-wp-customize-nav-menu-location-control.php:
    WP_Customize_Nav_Menu_Location_Control::render_content()
  • wp-includes/l10n.php:
    wp_dropdown_languages()
  • wp-admin/includes/theme-install.php:
    install_theme_search_form()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::months_dropdown()
  • wp-admin/includes/ms.php:
    mu_dropdown_languages()
  • wp-admin/includes/ms.php:
    choose_primary_blog()
  • wp-admin/includes/plugin-install.php:
    install_search_form()
  • wp-admin/includes/template.php:
    touch_time()
  • wp-admin/includes/template.php:
    page_template_dropdown()
  • wp-admin/includes/template.php:
    parent_dropdown()
  • wp-admin/includes/media.php:
    media_upload_library_form()
  • wp-admin/includes/meta-boxes.php:
    post_submit_meta_box()
  • wp-admin/includes/class-wp-media-list-table.php:
    WP_Media_List_Table::get_views()
  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::extra_tablenav()
  • wp-admin/custom-background.php:
    Custom_Background::admin_page()
  • wp-includes/category-template.php:
    wp_dropdown_categories()
  • wp-includes/widgets/class-wp-nav-menu-widget.php:
    WP_Nav_Menu_Widget::form()
  • wp-includes/widgets/class-wp-widget-tag-cloud.php:
    WP_Widget_Tag_Cloud::form()
  • wp-includes/widgets/class-wp-widget-pages.php:
    WP_Widget_Pages::form()
  • wp-includes/widgets/class-wp-widget-links.php:
    WP_Widget_Links::form()
  • wp-includes/widgets.php:
    wp_widget_rss_form()
  • wp-includes/user.php:
    wp_dropdown_users()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::render_content()
  • wp-includes/media-template.php:
    wp_print_media_templates()
  • Show 19 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 2You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    
    <!-- Testing the values with if() -->
    <select name="options[foo]">
    	<option value="1" <?php if ( $options['foo'] == 1 ) echo 'selected="selected"'; ?>>1</option>
    	<option value="2" <?php if ( $options['foo'] == 2 ) echo 'selected="selected"'; ?>>2</option>
    	<option value="3" <?php if ( $options['foo'] == 3 ) echo 'selected="selected"'; ?>>3</option>
    </select>
     
    <!-- Using selected() instead -->
    <select name="options[foo]">
    	<option value="1" <?php selected( $options['foo'], 1 ); ?>>1</option>
    	<option value="2" <?php selected( $options['foo'], 2 ); ?>>2</option>
    	<option value="3" <?php selected( $options['foo'], 3 ); ?>>3</option>
    </select>
    
    

上一篇:seems_utf8()

下一篇:self_admin_url()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!