在我的应用程序中,我需要更改 <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-plugin 3.5.1。 如何获得动态输出?
最佳答案
注意:这不是最好的方法。
但是删除订阅和 onBeforeTopics
属性。为提交按钮添加id并绑定(bind)点击事件。
<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>
关于java - struts2-jquery 标签中无法识别动态输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18270388/