2013-03-13 33 views
0

所以,我一直在用jsfiddle中的這個重定向生成器來擺弄一下,得到了我想要的東西。我試圖用它創建一個html頁面,但我無法使它工作。 http://jsfiddle.net/wVUhN/2/我在做什麼錯? JSFiddle中的工作不在我的HTML頁面中?

我還是相當新的jquery。 我的redirect.html頁面代碼。

<html> 
<head> 
<title>Redirect Test</title> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script> 
<script type="text/javascript"> 
$("#submit").click(function(){ 
    theurl = $("#theurl").val(); 
    $("textarea#newvalue").val('<html><head><meta HTTP-EQUIV="Refresh" CONTENT="0; URL="'+theurl+'"></head><body>This page has been moved.<p><a href="'+theurl+'">IF YOU ARE NOT REDIRECTED, PLEASE CLICK HERE.</a></body></html>');  
}); 
</script> 
</head> 
<body> 

<input type="text" id="theurl" placeholder="enter URL" /><button id="submit">Create Redirect</button> 
<br> 
<textarea id="newvalue"></textarea> 


</body> 
</html> 

LIVE網址:http://buildlinux.com/frontline/redirect.html

+0

什麼不正確工作? – Kamil 2013-03-13 00:28:34

+0

* How *不起作用?什麼在JS控制檯? – 2013-03-13 00:28:37

+0

我添加了該帖子的實時網址,點擊按鈕時什麼也沒有發生。 – Vernard 2013-03-13 00:33:50

回答

3

你應該把你的代碼文件準備好處理程序中:

$(document).ready(function(){ 
    // ... 
}) 

另外,較短的方法:

$(function() { 
    $("#submit").click(function() { 
     theurl = $("#theurl").val(); 
     $("textarea#newvalue").val('<html><head><meta HTTP-EQUIV="Refresh" CONTENT="0; URL="' + theurl + '"></head><body>This page has been moved.<p><a href="' + theurl + '">IF YOU ARE NOT REDIRECTED, PLEASE CLICK HERE.</a></body></html>'); 
    }); 
}); 
+0

試過這個,沒有變化。 – Vernard 2013-03-13 01:02:35

+1

@Vernard似乎現在工作在[頁面](http://buildlinux.com/frontline/redirect.html) – hjpotter92 2013-03-13 01:03:26

+0

必須是我的緩存,謝謝。 – Vernard 2013-03-13 01:08:17

0

只需添加自定義腳本在<body>的末尾(</body>之前)或用.onload做。它在JSfiddle中工作,因爲默認情況下設置了onLoad選項。

+0

好的,我將腳本移到了body標籤中,但沒有任何改變。問題仍然存在。有任何想法嗎? @ divoom12 – Vernard 2013-03-13 00:56:26

相關問題