0

例:

<button id="banButton{$id}"onclick="deletePhoto({$id}, {$picture_path});">BAN {$id}</button>

</body>タグの前に:

<script type="text/javascript" src="../profile/theme/js/jquery.js"></script>

<script type="text/javascript">

function deletePhoto(id, pic_path) {
    alert("test");
    $.post("ajax.php", { toid: toid, pic_path: pic_path });
}

$(document).ready(function() {
    alert("test2");

});


</script>

レンダリングされた HTML は次のようになります。

<button id="banButton508" onclick="deletePhoto(508, profile_photos/686733/1_4044.jpg);">BAN 508</button> <img src="../profile/pics/686725/2_3234.jpg" width="150" height="150"/>

ページのロード時に「test2」アラートが表示されますが、ボタンをクリックしても関数は実行されません (アラートも表示されません)。

理由はありますか?

編集:picture_pathを引用符で囲みました

<button id="banButton{$id}" class="banButton" onclick="deletePhoto({$id}, "{$picture_path}");">BAN {$id}</button>

まだこれで動作していません。

4

4 に答える 4

0

次のコードは正常に動作しています

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <title>Test</title>
  </head>

<body>

<button id="banButton508" onclick="deletePhoto(508, 'profile_photos/686733/1_4044.jpg');">BAN 508</button> <img src="../profile/pics/686725/2_3234.jpg" width="150" height="150"/>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js "></script>

<script type="text/javascript">

function deletePhoto(id, pic_path) {
alert("test"+pic_path);
$.post("ajax.php", { toid: toid, pic_path: pic_path });
}

$(document).ready(function() {
  alert("test2");

});


</script>
 </body>

于 2013-10-12T10:15:28.547 に答える
0

関数を他のすべてと一緒にドキュメント準備完了関数内に配置してみてください。

$(document).ready(function(){
function deletePhoto(id, pic_path) {
    alert("test");
    $.post("ajax.php", { toid: toid, pic_path: pic_path });
}
});
于 2013-10-12T10:06:53.757 に答える