我只是写一个代码来显示一个URL点击一个按钮。以下是我对于编写的代码:url不会显示在jquery
<!DOCTYPE html>
<html>
<head>
<title>URL Shortener Service</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$('#shortenit').click(sendURL);
});
function sendURL(){
var longurl = $('#longurl').val();
$('#shorturl').html(longurl);
}
</script>
</head>
<body>
<h1 align="center">URL Display</h1>
<form align="center" id="urlform">
<label>Please enter your long URL below</label><br />
<input type = "text" id="longurl" name ="longurl"/><br />
<input type = "submit" id="shortenit" value="Shorten"/>
</form>
<h3 align="center" id="shorturl"></h3>
</body>
</html>
在上面的代码中,当用户点击ID为#shortenit按钮会触发功能sendURL()这需要#longurl值并将其打印在具有#shorturl id的标签中。
每当我输入一些URL(或文本),它只是显示一瞬间然后它消失。任何人都可以告诉我我错了哪里?
而我甚至试图使用jQuery $ .get()方法将此URL发送到PHP,所以我确实需要获取URL。请告诉我如何。
取消表单提交 – mplungjan 2014-09-20 05:15:29