所以,我一直在jsfiddle中使用这个重定向生成器摆弄一下,得到了我想要的东西。我正在尝试用它创建一个html页面,但是我无法让它工作。 http://jsfiddle.net/wVUhN/2/
我仍然是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>
答案 0 :(得分: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>');
});
});
答案 1 :(得分:0)
只需在<body>
(</body>
之前)的末尾添加自定义脚本,或使用.onload执行此操作。它适用于JSfiddle,因为有onLoad选项,默认设置。