Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
问题,在需要第三个'&引用; 简短的回答是使用反斜杠转义,如下所示: <script type="text/javascript"> $('input[id=image_file]').change(function() { $('#photoCover').val($(this).val()); }); </script> <?php echo ' <input type="file" name="image_path" style="visibility:hidden;" id="image_file"> <div class="input-append"> <input id="photoCover" class="input-large" type="text"> <a class="btn" onclick="$(\'input[id=image_file]\').click();">Browse</a> </div> <script type="text/javascript"> $(\'input[id=image_file]\').change(function() { $(\'#photoCover\').val($(this).val()); }); </script> '; ?>_Php_Javascript - Fatal编程技术网

问题,在需要第三个'&引用; 简短的回答是使用反斜杠转义,如下所示: <script type="text/javascript"> $('input[id=image_file]').change(function() { $('#photoCover').val($(this).val()); }); </script> <?php echo ' <input type="file" name="image_path" style="visibility:hidden;" id="image_file"> <div class="input-append"> <input id="photoCover" class="input-large" type="text"> <a class="btn" onclick="$(\'input[id=image_file]\').click();">Browse</a> </div> <script type="text/javascript"> $(\'input[id=image_file]\').change(function() { $(\'#photoCover\').val($(this).val()); }); </script> '; ?>

问题,在需要第三个'&引用; 简短的回答是使用反斜杠转义,如下所示: <script type="text/javascript"> $('input[id=image_file]').change(function() { $('#photoCover').val($(this).val()); }); </script> <?php echo ' <input type="file" name="image_path" style="visibility:hidden;" id="image_file"> <div class="input-append"> <input id="photoCover" class="input-large" type="text"> <a class="btn" onclick="$(\'input[id=image_file]\').click();">Browse</a> </div> <script type="text/javascript"> $(\'input[id=image_file]\').change(function() { $(\'#photoCover\').val($(this).val()); }); </script> '; ?>,php,javascript,Php,Javascript,希望这有帮助。你可以像这样逃过“和”: <script type="text/javascript"> $('input[id=image_file]').change(function() { $('#photoCover').val($(this).val()); }); </script> <?php echo ' <input type="file" name="image_path" style="visibility:hidde

希望这有帮助。

你可以像这样逃过

<script type="text/javascript">
   $('input[id=image_file]').change(function() {
   $('#photoCover').val($(this).val());
   });
</script>
<?php
echo '
<input type="file" name="image_path" style="visibility:hidden;" id="image_file">
<div class="input-append">
<input id="photoCover" class="input-large" type="text">
<a class="btn" onclick="$(\'input[id=image_file]\').click();">Browse</a>
</div>
<script type="text/javascript">
$(\'input[id=image_file]\').change(function() {
   $(\'#photoCover\').val($(this).val());
});
</script>
'; 
?>
这样您可以得到3种不同的报价:

$html = ' " \" \' ';
$html='1!'
$(\'input[id=image\u file]\')。更改(函数(){
$(\'\'photoCover\').val($(this.val());
});
';
在javascript代码中使用转义qoutation时也要小心,因为它位于PHP字符串中:

$html = '<script type="text/javascript">
   $(\'input[id=image_file]\').change(function() {
   $(\'#photoCover\').val($(this).val());
   });
</script>';
$html='1!'
var=\'此文本有\\\'单引号:)\';
';
试试这个。这会有用的。
$html = '<script type="text/html">
    var = \'This text has \\\'quoted\\\' single quotes :)\';
</script>';
echo'
浏览
$(“输入[id=image\u文件]))。更改(函数(){
$(“#photoCover”).val($(this.val());
});
'; 
?>

我不知道您为什么要在PHP中重复这一点,但您可以这样做:

echo '

<input type="file" name="image_path" style="visibility:hidden;" id="image_file">
<div class="input-append">
<input id="photoCover" class="input-large" type="text">
<a class="btn" onclick="$(\'input[id=image_file]\').click();">Browse</a>
</div>

<script type="text/javascript">
$("input[id=image_file]").change(function() {
$("#photoCover").val($(this).val());
});
</script>

'; 
?>

浏览
$('input[id=image_file]')。更改(函数(){
$('#photoCover').val($(this.val());
});

或者,您可以使用
herdoc
语法:

<?php
    // PHP Code
    // In a PHP file, anything outside of PHP tags just gets echoed
?>

<input type="file" name="image_path" style="visibility:hidden;" id="image_file">
<div class="input-append">
  <input id="photoCover" class="input-large" type="text">
    <a class="btn" onclick="$('input[id=image_file]').click();">Browse</a>
</div>

<script type="text/javascript">
   $('input[id=image_file]').change(function() {
   $('#photoCover').val($(this).val());
   });
</script>

<?php
    // PHP Code
?>

由于这是PHP字符串构造中的常见问题,因此我将保留以下示例:

<?php

$html = <<<HTML

<input type="file" name="image_path" style="visibility:hidden;" id="image_file">
<div class="input-append">
  <input id="photoCover" class="input-large" type="text">
    <a class="btn" onclick="$('input[id=image_file]').click();">Browse</a>
</div>

<script type="text/javascript">
   $('input[id=image_file]').change(function() {
   $('#photoCover').val($(this).val());
   });
</script>

HTML;

echo $html;

?>
上面的示例是一个语法错误,因为字符串在预期时间之前已关闭。但是,如果字符串中的单引号被转义,则它将有效并显示为:

echo 'I want this text to show my ' in the sentence';
其他方法是在双引号和单引号之间来回切换:

echo 'I want this text to show my \' in the sentence';
//output : I want this text to show my ' in the sentence
但有时你需要更多,而且做以下事情看起来很难看:

echo "This will show my ' in the sentence";
//output : This will show my ' in the sentence
因此,请记住转义。HTML的另一种方法是退出PHP以显示它(有时不是选项):


在这里显示一些html

或者干脆

<?php if(true) : ?>
<p>Show some html <?php echo $var;?> here</p>
<?php endif; ?>


这可以通过多种方式完成,并且可以避免在
echo

中对引号进行杂耍看起来您正在寻找herdeoc语法。herdeoc语法的作用类似于第三种类型的
'


echo为什么不直接回显动态部分,而将其余部分保留为HTML/JavaScript?这似乎是一个PHP问题,而不是JS问题。您可以避开需要回显的
<代码>\'
我可以试着在什么地方停止回音?你说的邪恶游侠是什么意思?
<?php if(true) : ?>
<p>Show some html <?php echo $var;?> here</p>
<?php endif; ?>
<?php
    //some code here
?>
<html>
</html>
echo <<<HEREDOC

<input type="file" name="image_path" style="visibility:hidden;" id="image_file">
<div class="input-append">
  <input id="photoCover" class="input-large" type="text">
    <a class="btn" onclick="$('input[id=image_file]').click();">Browse</a>
</div>

<script type="text/javascript">
   $('input[id=image_file]').change(function() {
   $('#photoCover').val($(this).val());
   });
</script>

HEREDOC;