Javascript 使用php变量在单击时进行明文输入
我想使用javascript函数在单击时清除文本输入 但是,当我在php中使用它时,会出现以下错误: 分析错误:语法错误,意外;onfocus=this.select on'T_CONSTANT_ENCAPSED_STRING,应为','或';'在 以下是我正在使用的代码:Javascript 使用php变量在单击时进行明文输入,javascript,php,input,onclick,Javascript,Php,Input,Onclick,我想使用javascript函数在单击时清除文本输入 但是,当我在php中使用它时,会出现以下错误: 分析错误:语法错误,意外;onfocus=this.select on'T_CONSTANT_ENCAPSED_STRING,应为','或';'在 以下是我正在使用的代码: <?php echo'<input type = "text" name = "mod_n_part" id = "mod_n_part" class="modifica-regole-n_part" oncli
<?php
echo'<input type = "text" name = "mod_n_part" id = "mod_n_part" class="modifica-regole-n_part" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'.$n_part.':this.value;" value = '.$n_part.' />';
?>
php变量是$n_部分,如您所见更改如下:
onclick="this.value='';"
致:
只需用两个反斜杠转义两个单引号,如图所示 像这样
nclick="this.value=\'\';"
^ ^ ------ Like that.
正确的代码
nclick="this.value=\'\';"
^ ^ ------ Like that.
echo '<input type = "text" name = "mod_n_part" id = "mod_n_part" class="modifica-regole-n_part" onclick="this.value=\'\';" onfocus="this.select()" onblur="this.value=!this.value?'.$n_part.':this.value;" value = '.$n_part.' />';