如何在Yii中将文本TbButton引导程序转换为CHtml::链接?下面是TbButton引导程序代码:
$this->widget('bootstrap.widgets.TbButton', array(
'label'=>'Data Protection Policy - Must Read for Consultant',
'type'=>'primary', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
'htmlOptions'=>array('class'=>'addContactBtn','onclick'=>'js:(function(){
$("#pdpaModal").modal({"show":true});
return false;
})();')));
我需要将上面的代码转换为CHtml:
CHtml::link("Change Status", "#", array("onClick"=>"(function(){
$("#pdpaModal").modal({"show":true});
return false;
})();"))
但是,我在onClick部分遇到了一个错误。有人能帮我修吗?谢谢
您需要在双引号中转义双引号。
任一:
CHtml::link("Change Status", "#", array("onClick"=>"(function(){
$('"#pdpaModal'").modal({'"show'":true});
return false;
})();"));
或
CHtml::link("Change Status", "#", array("onClick"=>'(function(){
$("#pdpaModal").modal({"show":true});
return false;
})();'));
阅读:http://php.net/manual/en/language.types.string.php