[JavaScript]指定要素の指定イベント発火
triggerEvent(element, eventName){ const evt = new CustomEvent(eventName, {bubbles:true,cancelable:true}); return element.dispatchEvent(evt); }
triggerEvent(element, eventName){ const evt = new CustomEvent(eventName, {bubbles:true,cancelable:true}); return element.dispatchEvent(evt); }
isBrowserBack(){ const perfEntries = performance.getEntriesByType("navigation"); let result = false; perfEntries.forEach((perfEntry) => { if(perfEntry.type == 'back_forward'){ result = true; } }); return result; }
getCart(){ return new Promise((resolve,reject) => { const url = 'url'; fetch(url) .then((response)=>{ if (!response.ok) { throw new Error(); } return response.json(); }) .then((json)=>{ resolve(json); }) .catch((error)=>{ reject(error); }); }); } this.getCart() .then((json)=>{ }) .catch((error)=>{ });
loop: for(i=0;i<10;i++){ for(key in item.properties){ if(key === 'break'){ break loop; } } }
文字列から漢字抽出
const str = 'ひらがな小林カタカナ漢字'; const pattern = /(\p{scx=Han}+)/ug; const matches = str.match(pattern); console.log(matches);
出力
(2) ['小林', '漢字']
function get_parents($post,$parents = array()) { if (!empty($post->post_parent)){ $parent = get_post($post->post_parent); array_unshift( $parents, $parent); return get_parents( $parent, $parents ); } return $parents; } function the_parents($post,$format) { $parents = get_parents($post); if(!empty($parents)){ foreach($parents as $i => $parent){ $html = $format; $html = preg_replace('/%permalink%/',get_permalink($parent->ID),$html); $html = preg_replace('/%title%/',esc_html($parent->post_title),$html); echo $html; } } }
function disable_jsonld_of_aioseo() { return true; } add_filter('aioseo_schema_disable', 'disable_jsonld_of_aioseo');
function custom_image_size() { add_image_size('news_pc',270,466,true); add_image_size('news_sp',335,168,true); add_image_size('newsdetail',340,170,true); } add_action('after_setup_theme', 'custom_image_size');
function add_admin_style() { wp_enqueue_script('admin_script', get_template_directory_uri().'/scripts/admin.js'); wp_enqueue_style('admin_style', get_template_directory_uri().'/style/admin.css'); } add_action('admin_enqueue_scripts', 'add_admin_style');