关于jquery取值问题(分不多了,大哥大姐都过来看看。。。。)

guoyangjie 2011-04-27 09:17:57
小弟测试过的
<script type="text/javascript">
function test(){
var text=$("#txt.name").attr("value");
alert(text);
}
</script>
<input type="text" id="txt.name" name="txt.name"/>
<input type="button" onclick="test()" value="测试">
只要带.的貌似都去不到值,求高手赐教,如果去掉.完全通过,并说明原因。和解决方案
...全文
114 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
guoyangjie 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 yuxh81 的回复:]
$("#txt.name")

这一句很矛盾。。。
还是先看一下jquery api吧
[/Quote]
一点不矛盾,是有这样的需求,我知道不能用那个名字,但是就像我说的那个兄弟说的的确是一个不错的变通之法,以后你可能也会遇到这样的问题的。。。。。。。
吉普赛的歌 社区高级成员 T9 2011-04-27
  • 打赏
  • 举报
回复

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function test() {
$name = $(document.getElementById("txt.name"));
alert($name.val());
}
</script>
</head>
<body>
<input type="text" id="txt.name" name="txt.name" value="name"/>
<input type="button" onclick="test()" value="测试">
</body>
</html>

别急, 低手来了.
上面我测试过了, 完全可以用的.
乌镇程序员 2011-04-27
  • 打赏
  • 举报
回复
完全不懂JSP,如果<input>元素的数量的固定的,可以通过别的选择符来定位,比如:
$("input[type='text']:eq(2)").val();  //取第3个文本框的值。
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
怎么没人来了。。。
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
现在我和struts集成后去某个字段的实体的某个属性都是有点的,是不是就是不能用jquery来做了?
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
这位高手,别走开。。。帮人帮到底咯。。。
ghost_Bright 2011-04-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 t5500 的回复:]
1.id属性的值不能含有点号吧,用下划线代替:txt_name
2.取值:

JScript code
var text = $("#txt_name").val();
[/Quote]

标识只能是:数字,字母,下划线组成,首字还不能是数字
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 t5500 的回复:]
1.id属性的值不能含有点号吧,用下划线代替:txt_name
2.取值:

JScript code
var text = $("#txt_name").val();
[/Quote]
如果和Struts集成代表 某个实体的属性的话 ,怎么办 ?用_可以表示嘛?
乌镇程序员 2011-04-27
  • 打赏
  • 举报
回复
1.id属性的值不能含有点号吧,用下划线代替:txt_name
2.取值:
var text = $("#txt_name").val();
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
一定要顶起来,别搞成下去啦,好心人留个足迹吧!
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
怎么没有动静啊。。。。都过来帮帮忙啊。。。。
吉普赛的歌 社区高级成员 T9 2011-04-27
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 guoyangjie 的回复:]

引用 10 楼 yenange 的回复:
JScript code

<!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/xh……
[/Quote]
好就应该叫哥
yuxh81 2011-04-27
  • 打赏
  • 举报
回复
$("#txt.name")

这一句很矛盾。。。
还是先看一下jquery api吧
guoyangjie 2011-04-27
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 yenange 的回复:]
JScript code

<!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">
<head>
<met……
[/Quote]
此兄弟 见解独到,不错不错

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧