大家都知道jsp可以与js交互,而反过来则不可以,原因不做赘述,但是我们可以曲线救国,例子如下:、
[color=green]一、“交互”发生在form表单中[/color]
这种方式比较常见了,在表单中设置一个<input type="hidden" name="test" id="test"/>
在js中设置这个隐藏表单的value就可以实现了。
[color=green]二、交互发生在传参中[/color]
<input type="radio" name="sendMsg" id="sendMeg1" value="1" checked οnclick="selectNoSendMsg(this.value)">给作者发送短消息<input type="radio" name="sendMsg" id="sendMeg0" value="0" οnclick="selectNoSendMsg(this.value)">不发送短消息
<input type="button"
onClick="javascript:location.href='<c:url value="***.do?sendMeg='+beginMovePost()"/>"
value="测试" style="font:icon" />
其中js部分:
var isSendMsg = 1 ;
function selectNoSendMsg(value){
if(value==0)
isSendMsg = 0 ;
}
function beginMovePost(){
var selectPar = document.getElementById("sendMeg"+isSendMsg);
if(selectPar){
alert(selectPar.value);
return selectPar.value;
}
}
[color=red]说明:[/color]
即在beginMovePost中通过返回已存在控件value的方式实现“交互”。
[color=green]一、“交互”发生在form表单中[/color]
这种方式比较常见了,在表单中设置一个<input type="hidden" name="test" id="test"/>
在js中设置这个隐藏表单的value就可以实现了。
[color=green]二、交互发生在传参中[/color]
<input type="radio" name="sendMsg" id="sendMeg1" value="1" checked οnclick="selectNoSendMsg(this.value)">给作者发送短消息<input type="radio" name="sendMsg" id="sendMeg0" value="0" οnclick="selectNoSendMsg(this.value)">不发送短消息
<input type="button"
onClick="javascript:location.href='<c:url value="***.do?sendMeg='+beginMovePost()"/>"
value="测试" style="font:icon" />
其中js部分:
var isSendMsg = 1 ;
function selectNoSendMsg(value){
if(value==0)
isSendMsg = 0 ;
}
function beginMovePost(){
var selectPar = document.getElementById("sendMeg"+isSendMsg);
if(selectPar){
alert(selectPar.value);
return selectPar.value;
}
}
[color=red]说明:[/color]
即在beginMovePost中通过返回已存在控件value的方式实现“交互”。