WordPres对前端页面调试时的两个PHP函数使用小技巧
<p><strong>函数esc_js()(过滤 Html 内嵌 JS)</strong><br>
参数</p>
<p>
$text</p>
<p>
(字符串)(必须)要过滤的字符串。</p>
<p>
默认值:None</p>
<p>
返回值</p>
<p>
(字符串)返回过滤后的字符串。</p>
<p>
例子</p>
<div>
<div>
<div id="highlighter_652896">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code><input type=</code><code>"text"</code> <code>value=</code><code>"<?php echo esc_attr( $instance['input_text'] ); ?>"</code> <code>id=</code><code>"subbox"</code> <code>onfocus=</code><code>"if ( this.value == '<?php echo esc_js( $instance['input_text'] ); ?>') { this.value = ''; }"</code> <code>onblur=</code><code>"if ( this.value == '' ) { this.value = '<?php echo esc_js( $instance['input_text'] ); ?>'; }"</code> <code>name=</code><code>"email"</code> <code>/></code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
更多</p>
<p>
此函数位于:wp-includes/formatting.php</p>
<p>
<strong>nocache_headers()(禁止浏览器缓存)</strong><br>
nocache_headers() 用来发送一个 header 头信息,告诉浏览器禁止缓存当前页面,一般在 Ajax 请求时使用,防止出现错误。</p>
<p>
用法</p>
<div>
<div>
<div id="highlighter_643302">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>nocache_headers();</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
属性</p>
<p>
此函数没有属性。</p>
<p>
返回值</p>
<p>
此函数无返回值。</p>
<p>
例子</p>
<div>
<div>
<div id="highlighter_787561">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
<div>
5</div>
<div>
6</div>
</td>
<td>
<div>
<div>
<code>function</code> <code>Bing_add_ajax(){</code>
</div>
<div>
<code> </code><code>nocache_headers();</code>
</div>
<div>
<code> </code><code>echo</code> <code>true;</code>
</div>
<div>
<code> </code><code>die</code><code>;</code>
</div>
<div>
<code>}</code>
</div>
<div>
<code>add_action( </code><code>'template_redirect'</code><code>, </code><code>'Bing_add_ajax'</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
其它</p>
<p>
此函数位于:wp-includes/functions.php</p>
頁:
[1]