【发布时间】:2009-12-29 06:02:35
【问题描述】:
我正在使用 jQuery 在 Drupal 中工作。如何在标签中插入 php $variable。
$(document).ready(function(){
$("#comment-delete-<?php print $variable ?>").click(function(){
$("div.comment-<?php print $variable ?> span.body").replaceWith("new text");
});
})
或
$(document).ready(function(){
$("#comment-delete-". $variable).click(function(){
$("div.comment-". $variable ." span.body").replaceWith("new text");
});
})
有几点需要澄清。 我在 Drupal 中运行,所以完整的代码如下所示:
<?php
drupal_add_js (
'$(document).ready(function(){
$("#comment-delete-"' print $comment->cid; ').click(function(){
$("div.comment-"' print $comment->cid; '" span.body").replaceWith("<span style=\'color: grey;\'>Please wait...</span>");
});
})',
'inline');
?>
但它仍然无法正常工作。
更新:我尝试了以下方法,但仍然无法正常工作
<?php
$testing = "42";
drupal_add_js (
'$(document).ready(function(){
$("#comment-delete-"'. $testing .').click(function(){
$("div.comment-"'. $testing .'" span.body").replaceWith("<span style=\'color: grey;\'>Please wait...</span>");
});
})',
'inline');
?>
如果我使用数字“42”而不是变量,它可以工作,但在使用变量时却不行……很奇怪。
【问题讨论】:
-
你试过了吗?第一种方法应该适合你
-
我在 Drupal,我正在使用 print $variable print $variable 但它不起作用
-
没关系...这行不通...但是正如您所见,我已经在 php 中了
-
我无法退出 插入一个 php 变量
-
你有几个错位的引号..