jQuery的标签使用

给标签赋值的方式1、JavaScript方式通过取id来辅助$("#xingmin").val(value);,2、jQuery方式,通过调用id来赋值document.getElementById("age").value=value;alert(userinfo.age);相当于android打log的方式,跳出提示页面,看能否运行到下一个方法。完整代码` function xxx(){ var value=userinfo.username; $("#t1").text(value); alert(value);

}
`,$(“#要赋值标签的id”).val()**js的标准格式**先从json中获取信息,然后再通过id来赋值。```

function ccc(){ //var value=userinfo.username; var i=0 $("td").each(function(){

	   if(i==1){
	     $(this).text(userinfo.username);
		 
	   }
	   if(i==3){
	     $(this).text(userinfo.age);
	   }
	   
	   if(i==5){
	     $(this).text(userinfo.sex);
	   }
	   i++;
	})       
}

这个方法是当标签没有id时,通过tb标签的位置来进行赋值,each是一种遍历方式,然后用一个变量,来循环判断第几个tb标签。接下来附上完整代码,一个表单使用

<html> <head> <script src="jquery-1.8.3.min.js"></script><!-- 引入js文件的方式--> <script src="userinfo.js"></script> <script> function xingMin(){ var value=userinfo.username; $("#xingmin").val(value); } function age(){ var value=userinfo.age; document.getElementById("age").value=value; alert(userinfo.age); }

function ccc(){
    //var value=userinfo.username;
	var i=0
    $("td").each(function(){
	
	   if(i==1){
	     $(this).text(userinfo.username);
		 
	   }
	   if(i==3){
	     $(this).text(userinfo.age);
	   }
	   
	   if(i==5){
	     $(this).text(userinfo.sex);
	   }
	   i++;
	})       
}

</script>
</head>
<body>
	
    <div style="background-color:red"> hehe simida  <img src="85.png"/></div>
    <div> <button id="button" onclick="ccc()" >点击后赋值</button>
	    <table border='1' >
		     <tr>
			    <td width="100px">姓名</td>
			    <td width="200px">    </td>
			    <td width="100px">年龄</td>
				<td width="200px">    </td>
				<td width="100px">性别</td>
				<td width="200px">     </td>
			 </tr>
		</table>
	</div>
	<div>
	<input  id ="xingmin" /> <a href="#" onclick="xingMin()"> 点击获取姓名</a>
    <input id ="age" value=""/> <a href="#" onclick="age()" > 点击获取年龄</a>
    </div>	
     	 <table border='1' >
		     <tr>
			    <th width="100px">姓名</th>
			   
			    <th width="100px" >年龄</th>
				
				<th width="100px" >性别</th>
				
			 </tr>
			 <tr>
			    <td width="100px">xxxx</td>
			   
			    <td width="100px" >xxxxxx</td>
				
				<td width="100px" >xxxxx</td>
				
			 </tr>
		</table>	
</body>

</html> ```

转载于:https://my.oschina.net/xpawn/blog/801345

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值