2013-12-12 16 views
0

我非常新的JavaScript - 主要是隻用它來返回一個頁面或去鏈接..直接用戶使用JavaScript +一個id PHP頁面

我得到了它的示例頁面上工作,現在我試圖讓它在我的網站上工作......但是,當鏈接被按下時,什麼都沒有發生......

這些文件存在於它們的鏈接位置。該腳本從示例中複製而來。

部首:

<script type="text/javascript" src="js/jquery-impromptu.min.js"></script> 
<link rel="stylesheet" media="all" type="text/css" href="css/jquery-impromptu.css" /> 

<script type="text/javascript"> 
function removeUser(id){ 
       var txt = 'Are you sure you want to remove this user?<input type="hidden" id="userid" name="userid" value="'+ id +'" />'; 

       $.prompt(txt,{ 
        buttons:{Delete:true, Cancel:false}, 
        close: function(e,v,m,f){ 

         if(v){ 
          var uid = f.userid; 

          window.location = "deletemember.php?id=" + id;         

         } 
         else{} 

        } 
       }); 
      } 
</script> 

LINK:

<a href='javascript:;' onclick='removeUser(544666);'>Delete</a> 
+0

什麼是不工作?一些錯誤信息? – Reeno

+0

它有什麼作用,即問題在哪裏?我會嘗試window.location.href和問題,是否有可能的相對網址。 – Chrisissorry

+0

它沒有做任何事情..沒有彈出,沒有重定向。 –

回答

1

檢查這個演示:https://github.com/trentrichardson/jQuery-Impromptu/blob/master/demos/user_manager.html

你應該做的是做一個功能。這個函數在用戶做某事時被調用,但是它應該包含一個ID。例如:

<a href="javascript:;" title="Edit User" class="edituser" onclick="editUser(4);">Edit</a> 

所以,你可以看到你會調用該函數 'editUser(4)',其中4是ID。

返回JS

function editUser(id){ 


} 

在此功能中添加你的一部分,你結束了這一點:

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

    <script type="text/javascript"> 

     function removeUser(id){ 
      var user = $('#userid'+id) 
      var fname = user.find('.fname').text(); 
      var lname = user.find('.lname').text(); 

      var txt = 'Are you sure you want to remove this user with id: '+id+'?'; 

      $.prompt(txt,{ 
       buttons:{Change:true, Cancel:false}, 
       submit: function(e,v,m,f){ 
        var flag = true; 
        if (v) { 

         window.location = "deletemember.php?id=" + id; 

        } 
        return flag; 
       } 
      }); 
     } 

    </script> 

    <a href='javascript:;' onclick='removeUser(544666);'>Delete</a> 

現在的ID是可用您window.location的。

+0

看起來像一個合法的好答案。 –

+0

如果我想在該函數中添加2個id(一個用於成員,一個用於俱樂部),以便代碼顯示「window.location =」deleteuser.php?id =「+ id +」&club =「+ clubid; 「 - 那可能嗎 ? –

+0

好的 - 所以我複製該腳本到我的網頁 - 以前我通過編輯樣本使用它..現在,當我點擊它(鏈接是相同的),但它無處(鉻的底部它說:「JavaScript :;「..但沒有任何反應......我複製了JavaScript和CSS文件,並鏈接到jQuery庫.. –

0

使用window.location.hrefwindow.location.replace

<script type="text/javascript"> 
function removeUser(id) { 
    var txt = 'Are you sure you want to remove this user?<input type="hidden" id="userid" name="userid" value="' + id + '" />'; 

    $.prompt(txt, { 
     buttons: { 
      Delete: true, 
      Cancel: false 
     }, 
     close: function (e, v, m, f) { 

      if (v) { 
       var uid = f.userid; 

       //window.location.href = "deletemember.php?id=" + uid; 
       window.location.replace("deletemember.php?id=" + uid); 

      } else {} 

     } 
    }); 
} 
</script> 

您可以閱讀有關的不同here

相關問題