为什么这在IE中不起作用 - 表单提交问题

时间:2009-10-11 19:22:38

标签: javascript forms

我在IE以外的所有浏览器中工作。为什么不起作用?

Here is the site

表格代码在这里:

<FORM name ="frontpagequestion">
<input class="" type="text" name="questiontitle" value="ask your question and press enter" onfocus="if(this.value == 'ask your question and press enter') {this.value = '';}" onblur="if (this.value == '') {this.value = 'ask your question and press enter';}" size = "100">
<input type="submit" style="position: absolute; left: -9999px" onClick="process();return false">
</FORM>

Javascript代码在这里:

function process(){
    var title = document.frontpagequestion.questiontitle.value;
    title = escape(title); 

    $.cookie("INPUTBOX",title);

    window.location = "/questions/ask";
}

在IE中 - 它只返回主窗体并且不提交输入框值。

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

更改URL的正确调用是window.location.href =“[url]”,AFAIK。

答案 1 :(得分:1)

仅仅因为IE没有在提交按钮上执行onClick事件。如果您从问题框中选中它,它将按预期工作。

你应该为&lt; form&gt;尝试onSubmit事件标签。这应该适用于所有浏览器。

答案 2 :(得分:0)

我注意到了一些事情。

a)提交按钮上的click事件返回false。返回false会取消事件的默认操作,因此在这种情况下返回false意味着不提交表单。

b)您的脚本设置了window.location,这将立即导致浏览器加载新页面,而不是提交表单。