我正在使用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