我正在使用jQuery在Drupal中工作。如何在标签中插入一个php $变量。
$(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");
});
})
有几件事情来clearify。 我在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”,而不是变量,它的工作原理,但不是。
你甚至尝试过吗?第一种方法应该为你工作 – 2009-12-29 06:04:40
我在Drupal中,我正在使用<?php drupal_add_js(' $(document).ready(function(){ $(“#comment-delete - ?> print $ variable < (“new text”); }); }) (“div.comment - ?> print $ variable <?php span.body”)。 ','一致'); ?> 但它不工作 – Tim 2009-12-29 06:12:10
没关系...这是行不通的...... 但你可以看到,我在PHP已经<?PHP drupal_add_js(***)?> – Tim 2009-12-29 06:13:46