【问题标题】:How to use placeholder in wordpress如何在wordpress中使用占位符
【发布时间】:2014-05-21 00:50:03
【问题描述】:

这个问题很清楚。我如何使用占位符中的文本,例如来自下面的脚本。我一直在寻找这个并没有找到解决方案。我们将不胜感激。

Theme-options.php 文件:

<input type="text" placeholder="1.jpg" name="director_image1"
value="<?php print get_option('director_image1');
?>" />

我正在使用 functions.php 来检索文件,然后在标题中回显它:

var image1=<?php $image1 = get_option('director_image1');?>
<?php if( $image1) : ?>
<?php echo "'".$image1."';"; ?>
<?php endif; ?>

然后我正在使用 javascript 文件中的图像。你能帮帮我吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    在 PHP 代码中为图像元素添加一个 id。使用getElementById 检索img 元素。

      $image1 = of_get_option('director_image1');
      if ($image1) echo "<img id=\"dir_image\" src=\"" . $image1 . "\" />";
    
      var image1 = document.getElementById('dir_image');
      if (image1) 
      {
       // do something ...
      }
    

    【讨论】:

      猜你喜欢
      • 2015-05-15
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 2022-11-07
      • 2013-12-18
      • 1970-01-01
      • 2014-01-05
      • 2020-12-25
      相关资源
      最近更新 更多