返回介绍

selected()

发布于 2017-09-11 10:20:46 字数 4835 浏览 1019 评论 0 收藏 0

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

Outputs the html selected attribute.


description

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' );
}

更新日志

Versiondescription
1.0.0Introduced.

相关函数

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>
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文