IE兼容DIV表单提交按钮?

时间:2013-05-17 13:37:46

标签: php javascript html internet-explorer

除IE8及更低版本外,我的表单适用于所有浏览器。这太令人沮丧了,我不知道解决它的最佳方法?

<div class="nextbutton" onclick="checkstep();">Okay, All Done Here &raquo;</div>

为什么这不做任何事情?这是下面的JS。这就像点击按钮时绝对没有任何效果。它甚至不承认它被按下了。上面的按钮代码是你认为的问题吗?任何帮助都会非常感激!

function setgender(genderval) {


document.getElementById('male').checked = false;
document.getElementById('female').checked = false;
document.getElementById('notsay').checked = false;

document.getElementById(genderval).checked = true;

document.getElementById('genderS').value = genderval;

}

function checkstep() {



document.getElementById('resultstep').innerHTML = "";

var step1doc = document.step1;

var jobtitle = step1.jobtitle.value;
var companyname = step1.companyname.value;
var nearestcity = step1.nearestcity.value;
var industry = step1.industry.value;
var country = step1.country.value;
var brief = step1.brief.value;
var month = step1.month.value;
var day = step1.day.value;
var birthyear = step1.birthyear.value;
var gender = document.getElementById('genderS').value;

var error = '0';

var e_jobtitle = '0';
var e_companyname = '0';
var e_nearestcity = '0';
var e_industry = '0';
var e_country = '0';
var e_brief = '0';
var e_month = '0';
var e_day = '0';
var e_birthyear = '0';
var e_gender = '0';

if ( jobtitle == '' ) { e_jobtitle = '1'; error = '1'; } else { e_jobtitle = '0'; }
if ( companyname == '' ) { e_companyname = '1'; error = '1'; } else { e_companyname = '0'; }
if ( nearestcity == '' ) { e_nearestcity = '1'; error = '1'; } else { e_nearestcity = '0'; }
if ( industry == '0' ) { e_industry = '1'; error = '1'; } else { e_industry = '0'; }
if ( country == '0' ) { e_country = '1'; error = '1'; } else { e_country = '0'; }
if ( brief == '' ) { e_brief = '1'; error = '1'; } else { e_brief = '0'; }
if ( month == '0' ) { e_month = '1'; error = '1'; } else { e_month = '0'; }
if ( day == '0' ) { e_day = '1'; error = '1'; } else { e_day = '0'; }
if ( birthyear == '0' ) { e_birthyear = '1'; error = '1'; } else { e_birthyear = '0'; }
if ( gender == '0' ) { e_gender = '1'; error = '1'; } else { e_gender = '0'; }

var setname = '';

if ( e_jobtitle == '1' ) {
    setname = "Your Job Title";
    document.getElementById('resultstep').innerHTML += "Please fill in <font color=red>"+setname+"</font><br>";
} else {}
if ( e_companyname == '1' ) {
    setname = "Company Name";
    document.getElementById('resultstep').innerHTML += "Please fill in <font color=red>"+setname+"</font><br>";
} else {}
if ( e_nearestcity == '1' ) {
    setname = "Your Nearest City";
    document.getElementById('resultstep').innerHTML += "Please fill in <font color=red>"+setname+"</font><br>";
} else {}
if ( e_industry == '1' ) {
    setname = "Industry";
    document.getElementById('resultstep').innerHTML += "You must set your <font color=red>"+setname+"</font><br>";
} else {}
if ( e_country == '1' ) {
    setname = "Country";
    document.getElementById('resultstep').innerHTML += "You must set your <font color=red>"+setname+"</font><br>";
} else {}
if ( e_brief == '1' ) {
    setname = "Brief";
    document.getElementById('resultstep').innerHTML += "You must set a <font color=red>"+setname+"</font><br>";
} else {}
if ( e_gender == '1' ) {
    setname = "Gender";
    document.getElementById('resultstep').innerHTML += "You must choose <font color=red>"+setname+"</font><br>";
} else {}
if ( ( e_month == '1' ) || ( e_day == '1' ) || ( e_birthyear == '1' ) ) {
    setname = "Birth Day";
    document.getElementById('resultstep').innerHTML += "You must set your <font color=red>"+setname+"</font><br>";
} else {}

if ( error == '0' ) {

document.getElementById('full_content').style.display = "none";
document.getElementById('loading_content').style.display = "";

setTimeout(getstep2, 2000);

} else { 
    document.getElementById('resultstep').innerHTML += "<br><br>";
}



}


function getstep2() {



    var updateStep1AR;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        updateStep1AR = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            updateStep1AR = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                updateStep1AR = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    updateStep1AR.onreadystatechange = function(){
        if(updateStep1AR.readyState == 4){
var updrez = updateStep1AR.responseText;




        }
    }


var upd_jobtitle = step1.jobtitle.value.replace(/&/g, "222111");
var upd_companyname = step1.companyname.value.replace(/&/g, "222111");
var upd_nearestcity = step1.nearestcity.value.replace(/&/g, "222111");
var upd_industry = step1.industry.value;
var upd_country = step1.country.value;
var upd_brief = step1.brief.value.replace(/&/g, "222111");
var upd_genderS = step1.genderS.value;
var upd_month = step1.month.value;
var upd_day = step1.day.value;
var upd_birthyear = step1.birthyear.value;

    var queryString = "jobtitle="+upd_jobtitle+"&companyname="+upd_companyname+"&nearestcity="+upd_nearestcity+"&industry="+upd_industry+"&country="+upd_country+"&brief="+upd_brief+"&genderS="+upd_genderS+"&month="+upd_month+"&day="+upd_day+"&year="+upd_birthyear;

    updnocache = Math.random();
    updateStep1AR.open("GET", "/ajax/update_profile.php?" + queryString + "&nocache=" + updnocache, true);
    updateStep1AR.send(null); 





document.getElementById('full_content').innerHTML = document.getElementById('step2page').innerHTML;
document.getElementById('step2page').innerHTML = '';
document.getElementById('full_content').style.display = '';
document.getElementById('loading_content').style.display = "none";

1 个答案:

答案 0 :(得分:0)

你总是可以在jQuery中做到这一点?它专为跨浏览器兼容而设计,实现起来非常简单。或者,如果您确定要使用javascript而不是使用div,请尝试使用元素:

<a href="javascript:checkstep()">Okay, All Done Here</a>

在jQuery中,您可以拥有以下内容:

<div id="nextStepButton">Okay, All Done Here</div>

jQuery的:

$('#nextStepButton').click(function(){
    checkstep();
});