-2
我有一個大問題。我使用2個文件,adminedit.php和adminedit.js。當JavaScript在adminedit.php everytings偉大的作品。但當我使用:Extarnal Javascript不起作用,但內部工作
<script language="javascript" src="js/adminedit.js"></script>
...我的代碼不起作用。 有建議嗎?謝謝!
這是我的javascript代碼:
$(document).ready(function() {
//********************* Edit User *********************
$(".edituser").click(function edituser() {
var ID=$(this).attr('id'); // get user ID
// hide text
$("#username_"+ID).hide(); // hide username text
$("#email_"+ID).hide(); // hide email text
$("#password_"+ID).hide(); // hide password text
$("#ip_"+ID).hide(); // hide ip text
// show span
$("#username_input_"+ID).show(); // show username span
$("#email_input_"+ID).show(); // show email span
$("#password_input_"+ID).show(); // show password span
$("#ip_input_"+ID).show(); // show ip span
})
$(".edit_tr").change(function()
{
var ID=$(this).attr('id'); // get user ID
var username=$("#username_input_"+ID).val(); // get username
var email=$("#email_input_"+ID).val(); // get email
var password=$("#password_input_"+ID).val(); // get password
var ip=$("#ip_input_"+ID).val(); // get ip
var dataString = 'edit='+ ID +'&username='+username+'&email='+email+'&password='+password+'&ip='+ip;
$("#username_"+ID).html('<img src="../style/load.gif" />'); // show loading icon
// verify if are blank fildes
if(username.length && email.length && password.length>0) {
// modify user info
$.ajax({
type: "POST",
url: "<?php echo $tubCMSadmin['adminedit']; ?>",
data: dataString,
cache: false,
success: function(html)
{
// if info was edited do this
$("#username_"+ID).html(username);
$("#email_"+ID).html(email);
$("#password_"+ID).html(password);
$("#ip_"+ID).html(ip);
$(".editbox").hide();
$(".spantext").show();
}
});
} else {
alert('Enter something.') // if are blank fildes
;}
});
$(".editbox").mouseup(function()
{
return false
});
// hide span and show text
$(document).mouseup(function()
{
$(".editbox").hide();
$(".spantext").show();
});
//********************* Delete User *********************
$(".deleteuser").click(function deleteuser()
{
var ID=$(this).attr('id'); // get user ID
var dataString = 'delete='+ ID;
// confirm to delete
if (confirm("Are you sure you want to delete")) {
// delete user
$.ajax({
type: "POST",
url: "<?php echo $tubCMSadmin['admindelete']; ?>",
data: dataString,
cache: false
});
// delete row from table
var row = document.getElementById(ID);
row.parentNode.removeChild(row);
} else {
// if not confirmed
return false
$(".editbox").hide();
$(".spantext").show();
}
});
});
這是PHP文件:
<tr id="<?php echo $user[$nr][1]; ?>" bgcolor="#f2f2f2" class="edit_tr">
<td class="edit_td"><!-- // new cell -->
<span id="username_<?php echo $user[$nr][1]; ?>" class="spantext"><?php echo $user[$nr][2]; ?></span>
<input type="text" value="<?php echo $user[$nr][2]; ?>" class="editbox inputusername" id="username_input_<?php echo $user[$nr][1]; ?>" />
</td>
<td class="edit_td"><!-- // new cell -->
<span id="email_<?php echo $user[$nr][1]; ?>" class="spantext"><?php echo $user[$nr][3]; ?></span>
<input type="text" value="<?php echo $user[$nr][3]; ?>" class="editbox inputemail" id="email_input_<?php echo $user[$nr][1]; ?>"/>
</td>
<td class="edit_td"><!-- // new cell -->
<span id="password_<?php echo $user[$nr][1]; ?>" class="spantext"><?php echo $user[$nr][5]; ?></span>
<input type="text" value="<?php echo $user[$nr][5]; ?>" class="editbox inputpassword" id="password_input_<?php echo $user[$nr][1]; ?>"/>
</td>
<td class="edit_td"><!-- // new cell -->
<span id="ip_<?php echo $user[$nr][1]; ?>" class="spantext"><?php echo $user[$nr][6]; ?></span>
<input type="text" value="<?php echo $user[$nr][6]; ?>" class="editbox inputip" id="ip_input_<?php echo $user[$nr][1]; ?>"/>
</td>
<td><!-- // new cell -->
<input type="button" class="edituser" id="<?php echo $user[$nr][1]; ?>">
</td>
<td><!-- // new cell -->
<input type="button" class="deleteuser" id="<?php echo $user[$nr][1]; ?>" onclick="deleteuser(this);">
</td>
</tr>
定義「不起作用」。是否產生錯誤? – Snuffleupagus
不,JavaScript不再完成任務。 – GAD
嘗試查看您的控制檯,如果腳本的路徑是正確的。另外我覺得'