简体   繁体   English

使用jQuery的Submit按钮在IE9和FF9中不起作用

[英]Submit button using jQuery not working in IE9 and FF9

This submit button works in both Safari and Chrome but not IE9 or FF9. 此提交按钮可在Safari和Chrome中使用,但不适用于IE9或FF9。

Submit button - 提交按钮-

 <img type="submit" src="lib/send_feedback.jpg" border="0" class="feedback-submit-img" onClick="javascript: validate(); return false;"/>

Related jQuery - 相关jQuery-

// Submit form to next page
function submitForm() {
//   document.forms["feedbackform"].submit();
    document.feedbackform.submit();
}
// Submit form and validate email using RFC 2822 standard
function validateEmail(email) { 
    // Modified version original from: http://stackoverflow.com/a/46181/11236
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
// Return true if email field is left unchanged
function originalText(email){
    var defaultMsg;
    defaultMsg = "Enter your email address (optional)";
    if(defaultMsg == email){
        return true;    
    }
    return false;
}
// Verify or decline with error message
function validate(){
    $("#result").text("");
    var email = $("#email").val();
    if ((validateEmail(email)) || originalText(email)) {
        w.value = screen.width;
        h.value = screen.height;
        submitForm();
    } else {
        $("#result").text(email + " is not a valid email.");
        $("#result").css("color", "red");
    }
    return false;
}
$("form").bind("submit", validate);

Also for what it's worth when I alter the submit button to be more basic to ensure it submits the hidden field that w and h are suppose to update are not filled in. 同样,当我更改提交按钮以使其更基本以确保它提交了w和h应该更新的隐藏字段时,这是值得的。

Here is the entire code and the CSS 这是完整的代码CSS

type isn't a valid attribute of the img tag: https://developer.mozilla.org/En/HTML/Element/Img type不是img标签的有效属性: https : //developer.mozilla.org/En/HTML/Element/Img

Instead I think you want a <input type="image" /> tag: https://developer.mozilla.org/en/HTML/Element/Input . 相反,我认为您需要一个<input type="image" />标签: https : //developer.mozilla.org/en/HTML/Element/Input

The <img type="submit" /> didn't work for me either but using a <input type="image" /> did: http://jsfiddle.net/HXrNb/1/ <img type="submit" />也不适合我,但是使用<input type="image" />http : //jsfiddle.net/HXrNb/1/

You can then just bind the validate() function to the submit event for the form: 然后,您可以将validate()函数绑定到表单的submit事件:

$('form').on('submit', function () {
    ...
    if ((validateEmail(email)) || originalText(email)) {
        ...
        return true;
    } else {
        ...
        return false;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM