我是Struts2的新手,但我经常遇到jQuery选择器无法访问我们在jsps中定义的任何Struts2标记的问题。
我假设它们在没有大量自定义代码或插件的情况下是不会集成的,但我还没有找到任何关于它的明确的书面内容。当我访问strut2-jQuery plugin页面时,他们提到最好在他们的常见问题中使用插件,但不是必需的。
我是不是漏掉了什么?如果我有一个元素的struts2标签,并尝试使用jQuery选择它,它看起来不起作用。我说的是一些基本元素,比如
$('form').find(':input').change(function() { ... //or
$('#testbutton').attr('disabled', true); //or
$('#formName').change(function() {
alert("Found form!");
});因此,当我查看查看源代码时,我看到了从标签生成的常规html代码,如果是来自struts2标签而不是具有相同jQuery选择器代码的常规html标签,我就无法使用选择器访问这些特定元素。
另一项,我使用类似的东西来引用jsp页面上的jQuery:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>发布于 2012-05-08 05:22:55
HTML是如何生成的与客户端(浏览器)无关,并且客户端不知道生成的DOM以外的任何内容。
如果有一个ID,或者是一个输入,jQuery就会找到它--我多年来一直在S2应用程序中使用普通的jQuery (和Prototype),没有任何问题。
还有一些地方不对劲。
编辑以显示JSP、呈现的HTML和控制台输出。
JSP:
<s:form action="simpleForm">
<s:textfield name="fname"/>
<s:submit value="Go!"/>
</s:form>呈现的超文本标记语言(假设默认的"xhtml"主题):
<form id="simpleForm" name="simpleForm" action="/simpleForm.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"></td>
<td><input type="text" name="fname" value="" id="simpleForm_fname"/></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="simpleForm_0" value="Go!"/>
</div></td>
</tr>
</table></form>一些控制台输出:
> $("form")
[<form id="simpleForm" name="simpleForm" action="/simpleForm.action" method="post">…</form>]
> $("form").find(":input")
[<input type="text" name="fname" value="d" id="simpleForm_fname">,
<input type="submit" id="simpleForm_0" value="Go!">]
> $("form").find("input") // Don't need the ":"
[<input type="text" name="fname" value="d" id="simpleForm_fname">,
<input type="submit" id="simpleForm_0" value="Go!">]https://stackoverflow.com/questions/10488912
复制相似问题