2015-02-24 39 views
0

我正在使用Zend Framework 2,我想在我的index.html上翻译一个字符串,当我将其悬停在span标签上时,它会显示一个工具提示。问题是这个值必须改变,因为我用ajax做了一个动作,并且我想显示另一种类型的消息。你看我的成功Ajax代码:在标签跨度中更改属性标题包括来自ajax的php

success: function (data, status) { 
       $(this).switchEyeSpan(thisRow); 
       var status = "success"; 
       var id = thisRow.attr('data'); 
       $(this).messageEntity(status, id, data.message); 
       var translate = "<?php echo $this->translate('tooltip_eye_pub'); ?>"; 
       if(ischecked) { 
        translate = "<?php echo $this->translate('tooltip_eye_hide'); ?>"; 
       } 
       $('.tooltip-'+id).attr('title', translate); 
      }, 

正如你可以看到我想要的是取决于该器isChecked变量标题从标签更改。

这是我的index.html文件:

<span data="<?php echo $center->id ?>" class="tooltip-<?php echo $center->id; ?> checkbox-published-span glyphicon <?php echo ($center->published == 0) ? 'glyphicon-eye-open' : 'glyphicon-eye-close'; ?>"> 
        </span> 

这段代码的结果正从Java脚本的PHP代码为字符串。我怎样才能改变这个字符串为PHP代码?

+1

我不知道你意识到PHP运行纯粹的服务器和JS在客户端上......如果你看到所呈现的页面(查看源代码),你需要必须在你的页面的所有文本请不要在 – mplungjan 2015-02-24 10:07:42

+0

中对它们进行Ajax处理缺省变量的值和初始化值是什么? – 2015-03-19 12:03:18

回答

1

将这些行移到ajax之外并尝试它是否工作?

var translate = "<?php echo $this->translate('tooltip_eye_pub'); ?>"; 
if(ischecked) { 
    translate = "<?php echo $this->translate('tooltip_eye_hide'); ?>"; 
}