比如下面的代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript" src="jquery.min.js"></script>
<script language="javascript">
$(document).ready(function(){
var hy=document.getElementById("p1").textContent
var hg=document.getElementById("button1").value
$("#button1").click(function(){
$('#div1').load('limeng.asp?nm='+hy);
});
});
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<button id="button1" type="button" value="68888">hgjg</button>
<div id="div1">这里现在是空的</div>
<p id="p1">zenmjgjjgjg</p>
</body>
</html>
用选择选择符号是无法获取的,$("#p1").textcontent,以及$("#button1").textcontent,而是使用最基本的getElementById方法,因此,使用$应该怎样获取呢,请相关朋友回答下哈,谢谢
var hy=$('#p1').text();//document.getElementById("p1").textContent
var hg=$('#button1').val();//document.getElementById("button1").value
textcontent是属性吗?$("#p1").attr("textcontent")试试。
$("#button1").text
仔细查看jquery api。
支持1楼,仔细查看一下
$("#id").val()
.text();
.val();
.html();
区别查看详细资料
.text();
.val();
.html();
区别查看详细资料
在IE下面用.html()。如果确实获取不到值,在IE下面用F12调试看对象的属性。