无论如何都会显示带有“display:none”样式的Div

时间:2010-02-17 15:41:57

标签: javascript html css

我有一个id为“hubspot-contact-form”的div。此div的显示样式为none。但是当页面加载时,无论如何都会出现div。任何人都可以帮我弄清楚如何在页面加载时隐藏此表单?这是整个页面。感谢。

<?php

    include ('includes/secure.php');
    include ('includes/globals.php');
    $thisPage = "contact";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php include ('includes/pageTitle.php') ?>
<script type="text/javascript" src="js/browserDetect.js"></script>
<script type="text/javascript">
<!--
if (BrowserDetect.browser == "Explorer")
{
    document.write("<link href='css/stylesIE.css' rel='stylesheet' type='text/css'>");
} else {
    document.write("<link href='css/styles.css' rel='stylesheet' type='text/css'>");
}
// -->
</script>

<script type="text/JavaScript">

function show(id)
{
     if (document.getElementById(id).style.display == 'none')
     {
          document.getElementById(id).style.display = '';
     }
}

function hide(id)
{
          document.getElementById(id).style.display = 'none';

}

</script>

<script language="JavaScript" type="text/JavaScript"><!--

function validateForm() {
with (document.contactForm) {
var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
if (name.value == "") alertMsg += "\nYour Name";
if (email.value == "") alertMsg += "\nEmail Address";
checkemail = email.value
AtPos = checkemail.indexOf("@")
StopPos = checkemail.lastIndexOf(".")

if (AtPos == -1 || StopPos == -1) {
    alertMsg += "\nProvide a Valid Email Address";
}
if (subject.options[subject.selectedIndex].value == "") alertMsg += "\nSubject";
if (comments.value == "") alertMsg += "\nMessage/Comments";
if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
alert(alertMsg);
return false;
} else {
return true;
} } }

// --></script>

<link rel="stylesheet" href="css/thickbox.css" type="text/css" media="screen" />

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/thickbox.js"></script>

</head>

<body class="site">

<DIV ID="dek"></DIV>

<SCRIPT TYPE="text/javascript">
<!--

//Pop up information box II (Mike McGrath (mike_mcgrath@lineone.net,  http://website.lineone.net/~mike_mcgrath))
//Permission granted to Dynamicdrive.com to include script in archive
//For this and 100's more DHTML scripts, visit http://dynamicdrive.com

Xoffset=-60;    // modify these values to ...
Yoffset= 20;    // change the popup position.

var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all

if (ns4)
skn=document.dek
else if (ns6)
skn=document.getElementById("dek").style
else if (ie4)
skn=document.all.dek.style
if(ns4)document.captureEvents(Event.MOUSEMOVE);
else{
skn.visibility="visible"
skn.display="none"
}
document.onmousemove=get_mouse;

function popup(msg,bak){
var content="<TABLE WIDTH=250 BORDER=0 class='infoBox'><TD ALIGN=left class='infoBoxText'>"+msg+"</TD></TABLE>";
yyy=Yoffset;
 if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"}
 if(ns6){document.getElementById("dek").innerHTML=content;skn.display=''}
 if(ie4){document.all("dek").innerHTML=content;skn.display=''}
}

function get_mouse(e){
var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
skn.left=x+Xoffset;
var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
skn.top=y+yyy;
}

function kill(){
yyy=-1000;
if(ns4){skn.visibility="hidden";}
else if (ns6||ie4)
skn.display="none"
}

//-->
</SCRIPT>
<div id="container">
    <div id="header">
        <?php include ('includes/header.php') ?>
    </div>
    <table border="0" cellpadding="0" cellspacing="0" height="500" class="showborder">
        <tr>
            <td align="left" valign="top" width="619">
                <img src="images/contactTITLE.gif" border="0" alt="Contact AOP"><br />
                <div id="scrollBorder">
                <div id="boxScroll">
                    <table border="0" cellpadding="0" cellspacing="0" width="598">
                        <tr>
                            <td align="left" valign="top" class="text">
                                <?php showStatus($_REQUEST['status']) ?>
                                <?php include ('includes/pageContent.php') ?>
                                <br><br>
                    <script type='text/javascript' language='javascript'>/* <![CDATA[ */
                       HubSpotFormSpamCheck_LeadGen_ContactForm_29555_m0 = function() {
                           var key = document.getElementById('LeadGen_ContactForm_29555_m0spam_check_key').value;
                           var sig = '';
                           for (var x = 0; x< key.length; x++ ) {
                                    sig += key.charCodeAt(x)+13;
                           }
                           document.getElementById('LeadGen_ContactForm_29555_m0spam_check_sig').value = sig;
                           // Set the hidden field to contain the user token
                           var results = document.cookie.match ( '(^|;) ?hubspotutk=([^;]*)(;|$)' );
                            if (results && results[2]) {
                                document.getElementById('LeadGen_ContactForm_29555_m0submitter_user_token').value =  results[2];
                            } else if (window['hsut']) {
                                document.getElementById('LeadGen_ContactForm_29555_m0submitter_user_token').value = window['hsut'];
                            }
                            return true;
                       };

                      showContactForm = function() {
//debugger;
                        var formDiv = document.getElementById('hubspot-contact-form');
                        var formType = document.getElementById('subject').value;

                        if(formType == 'General Feedback' || formType == 'General Patent Study' || formType == 'Specific Patent Study') {
                          formDiv.style.display = 'block';
                          } else {
                            //formDiv.innerHTML = '';
                          }
                        }
                    /*]]>*/</script>

                                    <tr>
                                        <td align="left">
                                            * Subject:<br><br>
                                        </td>
                                        <td width="10"></td>
                                        <td align="left">
                                            <select name="subject" id="subject" class="field">
                                                <?php if ($_REQUEST['subject'] != "") { ?>
                                                    <?=$_REQUEST['subject']?>
                                                <?php } ?>
                                                <option value="">--SELECT--</option>
                                                <option value="General Feedback" onclick="showContactForm()">General Feedback</option>
                                                <option value="Website/Technical" onclick="showContactForm()">Website/Technical</option>
                                                <option value="General Patent Study" onclick="showContactForm()">General Patent Study</option>
                                                <option value="Specific Patent Study" onclick="showContactForm()">Specific Patent Study</option>
                                                <option value="Profit Sharing" onclick="showContactForm()">Profit Sharing</option>
                                            </select><br><br>
                                        </td>
                                    </tr>

                <div id="hubspot-contact-form" style="display: none;">
                   <form action="http://info.articleonepartners.com/Default.aspx?app=iframeform&hidemenu=true&ContactFormID=29555" method="post">
                      <input type="hidden" name="FormSubmitRedirectURL" id="FormSubmitRedirectURL" value="http://www.articleonepartners.com/contact.php?status=contact_request_has_been_sent" >
                      <input type="hidden" name="Lead_Src" id="LeadSrc" value="Contact Us" />
                      <input type="hidden" id="LeadGen_ContactForm_29555_m0submitter_user_token" name="LeadGen_ContactForm_29555_m0submitter_user_token"  value="" />
                      <input type="hidden" name="ContactFormId"  value="" />
                      <input type="hidden" id="LeadGen_ContactForm_29555_m0spam_check_key" name="LeadGen_ContactForm_29555_m0spam_check_key"  value="hjdrmdpfjkflkpjigdjonkqqpjinqssqr" />
                      <input type="hidden" id="LeadGen_ContactForm_29555_m0spam_check_sig" name="LeadGen_ContactForm_29555_m0spam_check_sig"  value="" />
                      <div class='ContactFormItems FormClassID_29555'>
                        <table border="3" cellspacing="0" cellpadding="2" class="showborder">
                          <tr>
                            <td align="right">First Name <span style="color: red"> *</span><br /><br /></td>
                            <td width="40"></td>
                            <td align="left"><input type="Text" name="LeadGen_ContactForm_29555_m0:FirstName" class="field StandardI AutoFormInput LeadGen_ContactForm_29555_m0_AutoForm" id="LeadGen_ContactForm_29555_m0_FirstName" value="" /><br /><br /></td>
                          </tr>
                          <tr>
                            <td align="right">Last Name <span style="color: red"> *</span><br /><br /></td>
                            <td width="40"></td>
                            <td align="left"><input type="Text" name="LeadGen_ContactForm_29555_m0:LastName" class="field StandardI AutoFormInput LeadGen_ContactForm_29555_m0_AutoForm" id="LeadGen_ContactForm_29555_m0_LastName" value="" /><br /><br /></td>
                          </tr>
                          <tr>
                            <td align="right">Email (we will keep your email completely private) <span style="color: red"> *</span></td>
                            <td width="40"></td>
                            <td align="left"><input type="Text" name="LeadGen_ContactForm_29555_m0:Email" class="field StandardI AutoFormInput LeadGen_ContactForm_29555_m0_AutoForm" id="LeadGen_ContactForm_29555_m0_Email" value="" /><br /><br /></td>
                          </tr>
                          <tr>
                            <td align="right">Phone (optional)<br /><br /></td>
                            <td width="40"></td>
                            <td align="left"><input type="Text" name="LeadGen_ContactForm_29555_m0:Phone" class="field StandardI AutoFormInput LeadGen_ContactForm_29555_m0_AutoForm" id="LeadGen_ContactForm_29555_m0_Phone" value="" /><br /><br /></td>
                          </tr>
                          <tr>
                            <td align="right" valign="top">Please Enter Your Message: <span style="color: red"> *</span><br /><br /></td>
                            <td width="40"></td>
                            <td align="left"><textarea type="Text" cols="40" rows="6" name="LeadGen_ContactForm_29555_m0:Message" class="StandardI AutoFormInput LeadGen_ContactForm_29555_m0_AutoForm" id="LeadGen_ContactForm_29555_m0_Message"  ></textarea><br /><br /></td>
                          </tr>
                          <tr><td></td><td width="40"></td><td><input onclick="return HubSpotFormSpamCheck_LeadGen_ContactForm_29555_m0();" class="FormSubmitButton" type="submit" name="LeadGen_ContactForm_Submit_LeadGen_ContactForm_29555_m0" value="Submit"></td></tr>
                      </table>
                    </div>
                  </form>
                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <img src="images/patentCatButtons.gif" width="617" height="32" border="0" alt="" usemap="#patentCatButtons_Map"><br />
                <map name="patentCatButtons_Map">
                <area shape="rect" alt="Full List" coords="496,0,617,32" href="list.php">
                <area shape="rect" alt="Patent Study Results" coords="295,0,496,32" href="patent_study_results.php">
                <area shape="rect" alt="Technology" coords="147,0,295,31" href="list.php?category=Technology">
                <area shape="rect" alt="Healthcare" coords="0,0,147,32" href="list.php?category=Healthcare">
                </map>
                </div>
            </td>
            <td width="15"></td>
            <td align="left" valign="top">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td align="left" valign="top">
                            <?php include ('includes/mainNav.php') ?>

                            <div id="homeText">
                                <img src="images/homeText.png" border="0"><br />
                            </div>

                            <?php include ('includes/searchBox.php') ?>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" valign="top">
                            <?php include ('includes/news2.php') ?>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    <div id="footerLong">
        <div id="footerTextLeft">
            <span onmouseover="show('copyright');return true;" onmouseout="hide('copyright');return true;">&copy; <?=date("Y")?>    ARTICLE ONE PARTNERS, ALL RIGHTS RESERVED</span><br />
            <div id="copyright" style="DISPLAY: none">
                The content contained on this site is provided to users "AS IS" without any express or implied warranty.<br />
            </div>
        </div>
        <?php include ('includes/footer.php') ?>
    </div>
</div>

</body>
</html>

2 个答案:

答案 0 :(得分:12)

您的divtable结构内启动。这是无效的,并保证弄乱渲染结果:

   </td>
   </tr>
   <!-- No-no! Either end the table or start a new table row. -->
   <div id="hubspot-contact-form" style="display: none;">

div可能会被忽略,并且以下tr被快速渲染,即使它们应该被隐藏。您需要先修复HTML。

您需要以某种方式将DIV集成到表中,方法是引入另一个表或使用tbody元素。

在寻找显示错误时,务必确保通过validator运行HTML。

答案 1 :(得分:1)

我注意到你在div之前缺少打开tr和td标签。尝试添加它们,看看是否能解决问题。