Onclick独立工作,但不在网页上

时间:2011-11-08 22:47:58

标签: javascript-events onclick onblur

在测试页面上,这可以找到静态变量:

<input class="txtSearch"
       onblur="if(this.value == '')this.value='Search' ;"
       onfocus="if(this.value == 'Search') this.value='';"
       value="Search" name="s" type="text" size="15" />

当我把它放在我的页面中,用动态php切换静态变量时,我得到一个白页。我是否在函数内正确地逃避了它们?

function wpsb_show_form($rtn = 0) { 
    $wpsb_flds = (get_option('wpsb_form_fields'));
    $add_link_lv = get_option("wpsb_link_love");
    $out = '<form action="#wpsbw" method="post">' . "\n";

    if (is_array($wpsb_flds)) {
        foreach ($wpsb_flds as $wpsb_k => $wpsb_v) {
            if (is_numeric($wpsb_k) && $wpsb_v) {
                $out .= '<ul class="optin">';
                $out .= '<li><span>Subscribe to our Newsletter</span></li>';
                $out .= '<li><input type="text" name="wpsb_fld['. $wpsb_k .']" id="wpsb_fld_'. $wpsb_k .'"  maxlength="64" class="txt" onblur="if(this.value == '') this.value="'. $wpsb_k .'" ;" onfocus="if(this.value == "'. $wpsb_k .'") this.value='';" value="'. $wpsb_k .'" /></label></li>' . "\n";
        }
    }
}

我是否需要转义javascript条件语句?

1 个答案:

答案 0 :(得分:0)

您需要在输出javascript的行中转义单引号(')。

记住:

print '\''; # output: '
print '"';  # output: "
print "'";  # output: '
print "\""; # output: "