jQuery中的text(),html(),val()的区别

text():获取或者改变指定元素的文本
html():获取或改变指定元素的html元素以及文本
val():获取或者改变指定元素的value值(一般是表单元素)
 
 
 
 
//点击数量变成文本框
	$(".txtNum").live("click",function(){
		//获取数量所在单元格
		$(this).parent().children().eq(1).html();
		//获取数量
		var amount = parseInt($(this).html());
		//创建文本框
		var txtN = '<input type="text" value="'+amount+'" size="3" class="txtN"/>';
		//将文本框替换数量
		$(this).replaceWith(txtN);
	})
	//失去焦点文本框变成<span>数量
	$(".txtN").live("blur",function(){
		//获取数量
		var amount = parseInt($(this).val());
		alert(amount);
		//创建span
		var txtNum = '<span class="txtNum">'+amount+'</span>';
		//将span替换文本框
		$(this).replaceWith(txtNum);
	});


猜你喜欢

转载自blog.csdn.net/qq_36992939/article/details/77970918