checked()
最后更新于:2021-11-25 20:28:08
checked( mixed$checked, mixed$current=true, bool$echo=true)Outputs the HTML checked attribute.
参数
- $checked
-
(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
源文件
文件: gc-includes/general-template.php
function checked( $checked, $current = true, $echo = true ) {
return __checked_selected_helper( $checked, $current, $echo, 'checked' );
}
<?php // Get an array of options from the database. $options = get_option( 'slug_option' ); // Get the value of this option. $checked = $options['self-destruct']; // The value to compare with (the value of the checkbox below). $current = 1; // True by default, just here to make things clear. $echo = true; ?> <input name="slug-option[self-destruct]" value="1" <?php checked( $checked, $current, $echo ); ?>/>