jquery使用的代码案例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>jquery的使用</title>
		<script src="js/jquery-1.12.1.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			table {
				margin-top: 15px;
				width: 500px;
				border: solid 1px black;
				border-collapse: collapse;
			}

			table .xh {
				width: 52px;

			}

			table .content {
				width: 300px;
			}
		</style>
	</head>
	<body>
		<input type="text" name="请输入你要访问的网址" id="wz" value="" />
		<button class="dj" type="button">点击</button>
		<p>如果你点我我就会消失,你再也找不到我了</p>
		<button type="button" id="cx">我不同意我要找到你</button>

		<div id="xiaohua">
			<table border="" cellspacing="" cellpadding="" id="biaoge">
				<tr>
					<th class="xh">序号</th>
					<th>内容</th>
					<th>更新时间</th>
				</tr>
				<!-- <tr>
					<td id="xh"></td>
					<td class="content" id="content"></td>
					<td id="gxsj"></td>
				</tr> -->
			</table>
		</div>

	</body>
	<script type="text/javascript">
		$('.dj').click(function() {
			// 获取网址通过id获取
			var wzurl = $('#wz').val();
			// console.log(wzurl);
			// console.log('nihao');
			// console.log(window.location.href);
			if (wzurl == 'haha') {
				console.log('haha');
				window.location.href = 'https://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gb18030&word=%C3%C0%C5%AE&fr=ala&ala=1&alatpl=normal&pos=0&dyTabStr=MCwzLDIsMSw0LDUsOCw3LDYsOQ%3D%3D';
			} else {
				window.location.href = 'https://' + wzurl;
			}

		})
		$('p').click(function() {
			$(this).hide();
		})
		$("#cx").click(function() {
			console.log('你为什么还不出现');
			$('p').show();
		})
		var apiKey = 'BrX5C6q3261b57e8041aeb0f77bb0ee29023377e8620309'
		$(document).ready(function() {
			//文档就绪事件 
			$.ajax({
				// url:"http://api.apishop.net/common/joke/getJokesByRandom",
				url: "xiaohua.json",
				type: "get",
				data: {
					'apiKey': apiKey,
					'pageSize': '20'
				},
				dataType: "json",
				success: function(res) {
					var temp = '';
					console.log(res.result);
					var list = res.result;
					for (var $i = 0; $i < list.length; $i++) {
						temp +=
							'<tr>' +
							'<td>' + list[$i].id + '</td>' +
							'<td>' + list[$i].content + '</td>' +
							'<td>' + list[$i].updateTime + '</td>' +
							'</tr>';
					}
					console.log(temp);
					$('#biaoge').append(temp);
					// alert("操作成功")
					// $('#biaoge').append(
					// 	'<tr>' + '你好世界' + '</tr>'
					// )
					// $('#xh').html(res.result[0].id);
					// $('#content').html(res.result[0].content);
					// $('#gxsj').html(res.result[0].updateTime);
					// for(i=0;i<res.result.length;i++){
					// 	$('#xh').html(res.result[i].id);
					// 	$('#content').html(res.result[i].content);
					// 	$('#gxsj').html(res.result[i].updateTime);
					// }

				},
				error: function(res) {
					alert("操作失败")
				}
			});
		});
	</script>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全栈开发crud师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值