克隆表单的php输出为纯文本

时间:2014-02-25 13:35:56

标签: php jquery html

我正在尝试使用jquery克隆一些html。

它工作正常,但它克隆的php正在以纯文本形式输出。

我有什么想法可以改变这个吗?

这是我到目前为止所获得的一个问题http://jsfiddle.net/vs8p5/5/

这是jquery

function updateClonedInput(index, element) {
$(element).appendTo("body").attr("id", "clonedInput" +  index);
$(element).find(">:first-child").attr("id", "show_upload_image_link_" + index);
$(element).find(">:first-child").attr("name", "kandibox_theme_hero_options[show_upload_image_link_" + index + "]");
$(element).find(">:first-child").attr("value", "<?php echo $hero_options['show_upload_image_link_" + index + "']; ?>");
$(element).find(">:first-child").next().attr("id", "show_upload_image_link_button_" + index);
}

$(document).on("click", "button.clone", function(){
var cloneIndex = $(".clonedInput").length + 1;
var new_Input = $(this).parents(".clonedInput").clone();
updateClonedInput(cloneIndex, new_Input);    
});
$(document).on("click", "button.remove", function(){
$(this).parents(".clonedInput").remove();

$(".clonedInput").each( function (cloneIndex, clonedElement) {
updateClonedInput(cloneIndex + 1, clonedElement);
})
});

这是html表单

<div id="upload_image_sets">
  <div id="clonedInput1" class="clonedInput">
  <input type="text" size="36" name="hero_options[upload_image_link_1]" value="<?php echo $hero_options['upload_image_link_1']; ?>" /> 
  <input id="show_upload_image_link_button_1" class="button upload_images" type="button" value="Upload Image" />
    <div class="actions">
      <button class="clone">Clone</button> 
      <button class="remove">Remove</button>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

为了像php一样输出删除&#34;&#34;围绕php代码:

 $(element).find(">:first-child").attr("value", <?php echo $hero_options['show_upload_image_link_" + index + "']; ?>);

否则它不会读取实际的php,它会自动将其转换为HTML文本。

我还注意到你在php代码之间插入jquery。在输出jquery之前,您必须关闭代码。如果上述仍然无法正常工作。这应该可以解决问题:

$(element).find(">:first-child").attr("value", <?php echo $hero_options['show_upload_image_link_?>index<?php ']; ?>);

希望这有帮助!

相关问题