在我的应用程序中,我需要动态地更改<s:textfield>的内容,我的代码如下所示:
<script type="text/javascript">
$.subscribe('before', function(event, data) {
$('#text').val('Text Changed by jQuery');
});
</script>
<s:form id="form2" action="textchange" >
<s:textfield id="text" name="text" value="Hello World!!!"/>
<sj:submit targets="result" onBeforeTopics="before" />
</s:form> 我期望的输出是
Text Changed by jQuery但我得到了
Hello World!!!我正在使用Struts2-jQuery-plugin3.5.1。如何获得动态输出?
发布于 2013-08-16 10:19:48
注意:这不是最好的方法。
但是删除订阅和onBeforeTopics属性。添加id以提交按钮并将单击事件绑定到该按钮。
<script type="text/javascript">
$(function(){
$("#form2Submit").click(function() {
$('#text').val('Text Changed by jQuery');
});
});
</script>
<s:form id="form2" action="textchange">
<s:textfield id="text" name="text" value="Hello World!!!" />
<sj:submit id="form2Submit" targets="result" />
</s:form>任何其他方式。与订阅一起使用<sj:a>标记。
<script type="text/javascript">
$(function(){
$.subscribe('before', function(event, data) {
$('#text').val('Text Changed by jQuery');
});
});
</script>
<s:form id="form2" action="textchange">
<s:textfield id="text" name="text" value="Hello World!!!" />
<sj:a targets="result" onClickTopics="before" formIds="form2" button="true">
Submit
</sj:a>
</s:form>发布于 2013-08-16 09:53:03
before在表单序列化后运行,因此使用旧值。您需要像这样修改代码
<script type="text/javascript">
$(document).ready(function(){
$('#before').click(function() {
$('#text').val('Text Changed by jQuery');
});
});
</script>
<s:div id="result"/>
<s:form id="form2" action="textchange" method="POST">
<s:textfield id="text" name="text" value="Hello World!!!"/>
<sj:submit id="before" targets="result" />
</s:form>https://stackoverflow.com/questions/18270388
复制相似问题