<form name="f" action="/servlet/PreProxy" >
<table>
<tr>
<td>
输入地址:
</td>
<td>
<input type="text" style="width: 340px; height: 22px;" class="bian" id='proxyUrl' name="proxyUrl" >
</td>
<td>
<input type="button" value="代理" id="su" >
</td>
</tr>
</table>
</form></div>
<script type="text/javascript"> var textObj = document.getElementById('proxyUrl');
var but = document.getElementById('su');
but.onclick=textObj.onkeypress = function createURl(event){
textObj.vaule=textObj.value.replace(/\./g,')');
try{
if (event.keyCode==13) {
alert(textObj.vaule);
document.forms[0].submit();
}
}catch(e){
}
}
</script>
我想的效果是:在文本框里按下回车或点击代理按钮 能过提交表单
还有就是把表单里有.号替换成 )
比如:我在文本框里输入 sei.se 应该提交sei)se
可提交的内容却是sei.se
但alert 打出来的文本值 是sei)se
为什么表单提交却不是呢
<table>
<tr>
<td>
输入地址:
</td>
<td>
<input type="text" style="width: 340px; height: 22px;" class="bian" id='proxyUrl' name="proxyUrl" >
</td>
<td>
<input type="button" value="代理" id="su" >
</td>
</tr>
</table>
</form></div>
<script type="text/javascript"> var textObj = document.getElementById('proxyUrl');
var but = document.getElementById('su');
but.onclick=textObj.onkeypress = function createURl(event){
textObj.vaule=textObj.value.replace(/\./g,')');
try{
if (event.keyCode==13) {
alert(textObj.vaule);
document.forms[0].submit();
}
}catch(e){
}
}
</script>
我想的效果是:在文本框里按下回车或点击代理按钮 能过提交表单
还有就是把表单里有.号替换成 )
比如:我在文本框里输入 sei.se 应该提交sei)se
可提交的内容却是sei.se
但alert 打出来的文本值 是sei)se
为什么表单提交却不是呢
要怎么要才能是提交替换后的值
用户在form的input tag里按回车健的时候,form就自动提交了。你的语句还没执行,form就已经送走了。
vaule --> value
alert(textObj.vaule);
// 加一句这个,你就明白了
alert(document.getElementById('proxyUrl').value); document.forms[0].submit();
}
以上证明实际上你proxyUrl的值没有改变。按下面的写试试
document.getElementById('proxyUrl').value = textObj.value.replace(/\./g,')');
……
but.onclick = textObj.onkeypress = function createURl(event){
textObj.vaule = textObj.value.replace(/\./g,')'); //应该是value,自定义属性的话提交会不会有问题?
try{
if (event.keyCode==13) { //只有回车的时候event.keyCode==13,点按钮是进不来的
alert(textObj.vaule);
document.forms[0].submit();
}
}catch(e){
}
}