按钮应设置网页中的文本。该怎么办?

Button should set the text in the webpage. What to do?

我在使用带功能的按钮时遇到问题。我只知道 java 应用程序,我正在努力学习 HTML 和 JavaScript。我希望按钮将条件语句中存在的文本设置到网页上,条件基于 select 框。

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<HTML>
    <HEAD>
        <TITLE>P-Block Chemical Reactions</TITLE>
    </HEAD>
    <BODY>

    <CENTER><FONT FACE="TIMES NEW ROMAN" COLOR="GREEN" size="50"><b><u>P-Block Chemical Reactions</u></b></font>
        <br><br><br><h2>Structure of P-Block</h2><br>
        <img src="http://2.bp.blogspot.com/-HNGbTyDrWso/UAGMqI2uY6I/AAAAAAAAAC0/mSWX5ZivvDk/s1600/Use%252Bnowwwww-723799.jpg">
        <br></center>
    <br>
    <form>
        <select id="Groups" name="Groups" >
            <option value="1">Group 13</option>
            <option value="2">Group 14</option>
            <option value="3">Group 15</option>
            <option value="4">Group 16</option>
            <option value="5">Group 17</option>
            <option value="6">Group 18</option></select>
        <button onClick="gr();">See</button></form>



    <script type="text/javascript">
                function gr()
                {
                var s = document.getElementById('Groups');
                        var g = s.options[s.selectedIndex].value;
                        if (g === 1)
                {
                document.write("<b><h3>Chemical Reactions for GROUP 13 :</h3></b><br>
                        < ul type = "disc" >
                        < li > Reaction with O < sub > 2 < /sub> <br>
                        Boron is unreactive in crystalline form.Aluminium forms a very thin oxide layer on the surface which protects the metal from further attack. < br > < br >
                        2E(s) + 3O < sub > 2 < /sub>(g) → 2E<sub>2</sub > O < sub > 3 < /sub>(s)       
                        (E = element) < br > < br >
                        < li > Reaction with N < sub > 2 < /sub><br>
                        With dinitrogen at high temperature these elements form nitrides. < br > < br >
                        2E(s) + N < sub > 2 < /sub>(g) → 2EN(s)    
                        (E = element) < br > < br >
                        < li > Reaction with acids and alkalies < br >
                        Boron does not react with acids and alkalies even at moderate temperature, but aluminium dissolves in mineral acids and aqueous alkalies and thus shows amphoteric character. < br > Aluminium dissolves in dilute HCl and liberates dihydrogen. < br > < br >
                        2Al(s) + 6HCl(aq) → 2Al < sup > 3 + < /sup>(aq) + 6Cl<sup>-</sup > (aq) < br > < br >
                        However, concentrated nitric acid renders aluminium passive by forming a protective oxide layer on the surface. < br > < br >
                        Aluminium also reacts with aqueous alkali and liberates dihydrogen. < br > < br >
                        2Al(s) + 2NaOH(aq) + 6H < sub > 2 < /sub>O(l) → 2Na<sup>+</sup > [Al(OH) < sub > 4 < /sub>]<sup>-</sup > (aq) + 3H < sub > 2 < /sub>(g)  <br><br>

                        < li > Reaction with halogens < br >
                        These elements react with halogens to form trihalides (except TlI < sub > 3 < /sub>).<br><br>
                                2E(s) + 3X < sub > 2 < /sub>(g) → 2EX<sub>3</sub > (s) & nbsp; & nbsp; & nbsp; & nbsp; (X = F, Cl, Br, I)
                                < /ul>");
                        }

                        else if (item === 2)
                        {
                        document.write("<b><h3>Chemical Reactions for GROUP 14 :</h3></b><br>
                                < ul type = "disc" >
                                < li > Reaction with O < sub > 2 < /sub> <br>
                                All members when heated in oxygen form oxides.There are mainly two types of oxides, i.e., monoxide and dioxide of formula MO and MO < sub > 2 < /sub> respectively. SiO only exists at high temperature. Oxides in higher Oxidation states of elements are generally more acidic than those in lower oxidation states.<br><br> The dioxides : CO<sub>2</sub > , SiO < sub > 2 < /sub> and GeO<sub>2</sub > are acidic, whereas SnO < sub > 2 < /sub> and PbO<sub>2</sub > are amphoteric in nature.Among monoxides, CO is neutral, GeO is distinctly acidic whereas SnO and PbO are amphoteric. < br > < br >
                                < li > Reaction with water < br >
                                Carbon, silicon and germanium are not affected by water.Tin decomposes steam to form dioxide and dihydrogen gas. < br > < br >
                                Sn + 2H < sub > 2 < /sub>O → SnO<sub>2</sub > + 2H < sub > 2 < /sub> <br><br>
                                Lead is unaffected by water, probably because of a protective oxide film formation. < br > < br >
                                < li > Reaction with halogen < br >
                                These elements can form halides of formula MX < sub > 2 < /sub> and MX<sub>4</sub > (where X = F, Cl, Br, I).Except carbon, all other members react directly with halogen under suitable condition to make halides.Most of the MX < sub > 4 < /sub> are covalent in nature. The central metal atom in these halides undergoes sp<sup>3</sup > hybridisation and the molecule is tetrahedral in shape.Exceptions are SnF < sub > 4 < /sub> and PbF<sub>4</sub > , which are ionic in nature. < br > PbI < sub > 4 < /sub> does not exist because Pb-I bond initially formed during the reaction does not release enough energy to unpair 6s<sub>2</sub > electrons and excite one of them to higher orbital to have four unpaired electrons around lead atom.Heavier members Ge to Pb are able to make halides of formula MX < sub > 2 < /sub>. Stability of dihalides increases down the group. Considering the thermal and chemical stability, GeX<sub>4</sub > is more stable than GeX < sub > 2 < /sub>, whereas PbX<sub>2</sub > is more than PbX < sub > 4 < /sub>. Except CCl<sub>4</sub > , other tetrachlorides are easily hydrolysed by water because the central atom can accomodate the lone pair of electrons from oxygen atom of water in d orbital.
                                < /ul><br><br>");
                        }

                        else if (item === 3)
                        {
                        document.write("<b><h3>Chemical Reactions for GROUP 15 :</h3></b><br>
                                < ul type = "disc" >
                                < li > Reaction with Hydrogen < br >
                                All the elements of Group 15 form hydrides of the type EH < sub > 3 < /sub> where E = N, P, As, Sb or Bi.<br> The stability of hidrides decreases from NH<sub>3</sub > to BiH < sub > 3 < /sub> which can be observed from their bond dissociation enthalpy. Consequently,the reducing character of the hydrides increases. Ammonia is only a mild reducing agent while BiH<sub>3</sub > is the strongest reducing agent amongst all the hydrides.Basicity also decreases in the order NH < sub > 3 < /sub> > PH<sub>3</sub > & gt; AsH < sub > 3 < /sub> > SbH<sub>3</sub > & ge; BiH < sub > 3 < /sub>.<br><br>

                                < li > Reaction with Oxygen < br >
                                All these elements form two types of oxides: E < sub > 2 < /sub>O<sub>3</sub > and E < sub > 2 < /sub>O<sub>5</sub > .The oxide in the higher oxidation state of the element is more acidic than that of lower oxidation state.Their acidic character decreases down the group.The oxides of the type E < sub > 2 < /sub>O<sub>3</sub > of nitrogen and phosphorus are purely acidic, that of arsenic and antimony amphoteric and those of bismuth is predominantaly basic. < br > < br >
                                < li > Reaction with Halogen < br >
                                These elements react to form two series of halides: EX < sub > 3 < /sub> and EX<sub>5</sub > .Nitrogen does not form pentahalide due to non - availability of the d - orbitals in its valence shell.Pentahalides are more covalent than trihalides.All the trihalides of these elements except those of nitrogen are stable.In case of nitrogen, only NF < sub > 3 < /sub> is known to be stable. Trihalides except BiF<sub>3</sub > are predominantly covalent in nature. < br > < br >
                                < li > Reaction with Metal < br >
                                All these elements react with metals to form their binary compounds exhibiting - 3 oxidation state, such as, Ca < sub > 3 < /sub>N<sub>2</sub > (Calcium nitride), Ca < sub > 3 < /sub>P<sub>2</sub > (Calcium phosphide), Na < sub > 3 < /sub>As<sub>2</sub > (Sodium arsenide), Zn < sub > 3 < /sub>Sb<sub>2</sub > (Zinc antimonide) and Mg < sub > 3 < /sub>Bi<sub>2</sub > (Magnesium bismuthide). < br > < br >
                                < /ul>");
                        }

                        else if (item === 4)
                        {
                        document.write("<b><h3>Chemical Reactions for GROUP 16 :</h3></b><br>
                                < ul type = "disc" >
                                < li > Reaction with Hydrogen < br >
                                All the elements of Group 16 form hydrides of the type H < sub > 2 < /sub>E (E = S, Se, Te, Po). Their acidic character increases from H<sub>2</sub > O to H < sub > 2 < /sub>Te. The increse in acidic character can be explained in terms of decrease in bond (H-E) dissociation enthalpy down the group. Owing to the decrease in bond (H-E) dissociation enthalpy down the group, the thermal stability of hydrides also decreases from H<sub>2</sub > O to H < sub > 2 < /sub>Po. All the hydrides except water possess reducing property and this character increases from H<sub>2</sub > S to H < sub > 2 < /sub>Te.<br><br>

                                < li > Reaction with Oxygen < br >
                                All these elements form oxides of the EO < sub > 2 < /sub> and EO<sub>3</sub > types where E = S, Se, Te or Po.Ozone (O < sub > 3 < /sub>) and sulphur dioxide (SO<sub>2</sub > ) are gases while selenium dioxide (SeO < sub > 2 < /sub>) is solid. Reducing property of dioxide decreases from SO<sub>2</sub > to TeO < sub > 2 < /sub>. SO<sub>2</sub > is reducing while TeO < sub > 2 < /sub> is an oxidising agent. Besides EO<sub>2</sub > type, sulphur, selenium and tellurium also form EO < sub > 3 < /sub> type oxides (SO<sub>3</sub > , SeO < sub > 3 < /sub>, TeO<sub>3</sub > ).Both types of oxides are acidic in nature. < br > < br >
                                < li > Reaction with Halogen < br >
                                Elements of Group 16 form a large number of halides of the type, EX < sub > 6 < /sub>, EX<sub>4</sub > and EX < sub > 2 < /sub> where E is an element of the group and X is a halogen. The stability of the halides decreases in the order F<sup>-</sup > & gt; Cl < sup > - < /sup> > Br<sup>-</sup > & gt; I < sup > - < /sup>. Amongst hexahalides, hexafluorides are the only stable halides. All hexafluorides are in gaseous nature. They have octahedral structure. Sulphur hexafluoride, SF<sub>6</sub > is exceptionally stable for steric reasons. < br >
                                Amongst tetrafluorides, SF < sub > 4 < /sub> is a gas, SeF<sub>4</sub > a liquid and TeF < sub > 4 < /sub> a solid. These fluorides have sp<sup>3</sup > d hybridisation and thus, have trigonal bipyramidal structures in which one of the equatorial positions is occupied by a lone pair of electrons.This geometry is also regarded as see - saw geometry. < br >
                                All elements except selenium form dichlorides and dibromides.These dihalides are formed by sp < sup > 3 < /sup> hybridisation and thus, have tetrahedral structure. The well known monohalides are dimeric in nature. Examples are S<sub>2</sub > F < sub > 2 < /sub>, S<sub>2</sub > Cl < sub > 2 < /sub>, S<sub>2</sub > Br < sub > 2 < /sub>, Se<sub>2</sub > Cl < sub > 2 < /sub> and Se<sub>2</sub > Br < sub > 2 < /sub>. These dimeric halides  undergo disproportionation as given below: <br><br>
                                2Se < sub > 2 < /sub>Cl<sub>2</sub > → SeCl < sub > 4 < /sub> + 3Se <br><br>
                                < /ul>");
                        }

                        else if (item === 5)
                        {
                        document.write("<li><b><h3>Chemical Reactions for GROUP 17 :</h3></b><br>
                                < ul type = "disc" >
                                < li > Reaction with Hydrogen < br >
                                They all react with hydrogen to give hydrogen halides but affinity for hydrogen decreases from fluorine to iodine.They dissolve in water to form hydrohali acids.The acidic strength of these acids varies in the order: HF & lt; HCl & lt; HBr & lt; HI.The stability of these halides decreases down the group due to decrease in bond (H - X) dissociation enthalpy in the order: H - F & gt; H - Cl & gt; H - Br & gt; H - I. < br > < br >
                                < li > Reaction with Oxygen < br >
                                Halogens form many oxides with oxygen but most of them are unstable.Fluorine forms two oxides OF < sub > 2 < /sub>, O<sub>2</sub > F < sub > 2 < /sub>. However, only OF<sub>2</sub > is thermally stable at 298 K.These oxides are essentially oxygen fluorides because of the higher electronegativity of fluorine than oxygen.Both are strong fluorinating agents.O < sub > 2 < /sub>F<sub>2</sub > oxidises plutonium to PuF < sub > 6 < /sub> and the reaction is used in removing plutonium as PuF<sub>6</sub > from spent nuclear fuel. < br >
                                Chlorine, bromine and iodineChlorine, bromine and iodine form oxides in which the oxidation
                                states of these halogens range from + 1 to + 7. A combination of kinetic and thermodynamic factors lead to the generally decreasing order of stability of oxides formed by halogens, I & gt; Cl & gt; Br.The higher oxides of halogens tend to be more stable than the lower ones. < br >
                                Chlorine oxides, Cl < sub > 2 < /sub>O, ClO<sub>2</sub > , Cl < sub > 2 < /sub>O<sub>6</sub > and Cl < sub > 2 < /sub>O<sub>7</sub > are highly reactive oxidising agents and tend to explode.ClO < sub > 2 < /sub> is used as a bleaching agent for paper pulp and textiles and in water treatment.<br>
                                The bromine oxides, Br < sub > 2 < /sub>O, BrO<sub>2</sub > , BrO < sub > 3 < /sub>  are the least stable halogen oxides (middle row anomally) and exist only at low temperatures. They are very powerful oxidising agents. The iodine oxides, I<sub>2</sub > O < sub > 4 < /sub>, I<sub>2</sub > O < sub > 5 < /sub>, I<sub>2</sub > O < sub > 7 < /sub> are insoluble solids and
                                decompose on heating.I < sub > 2 < /sub>O<sub>5</sub > is a very good oxidising agent and is
                                used in the estimation of carbon monoxide. < br > < br >
                                < li > Reaction with Metals < br >
                                Halogens react with metals to form metal halides.For example, bromine reacts with magnesium to give magnesium bromide. < br > < br >
                                Mg(s) + Br < sub > 2 < /sub>(l)  → MgBr<sub>2</sub > (s) < br > < br >
                                The ionic character of the halides decreases in the order MF & gt;
                                MCl & gt; MBr & gt; MI where M is a monovalent metal.If a metal exhibits
                                more than one oxidation state, the halides in higher oxidation
                                state will be more covalent than the one in lower oxidation state.
                                For example, SnCl < sub > 4 < /sub>, PbCl<sub>4</sub >
                                , SbCl < sub > 5 < /sub> and UF<sub>6</sub >
                                are more covalent than SnCl < sub > 2 < /sub>
                                , PbCl < sub > 2 < /sub>, SbCl<sub>3</sub >
                                and UF < sub > 4 < /sub> respectively.<br><br>

                                < li > Reaction with Halogens < br >
                                Halogens combine amongst themselves to form number of compounds known as interhalogens of the types XX < sup > ` < /sup>, XX<sup>`</sup > < sub > 3 < /sub>, XX<sup></sup > < sub > 5 < /sub> and XX<sup>`</sup > < sub > 7 < /sub> where X is a larger size halogen and X<sup>`</sup > is a smaller size halogen. < br > For example: & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; I < sub > 2 < /sub>    + Cl<sub>2</sub > & nbsp; → 2ICl < br > & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; (equimolar) < br > < br >
                                < /ul>");
                        }

                        }
    </script>





</body>
</html>

问题出在document.write

你不能做:document.write("<a href="website.html"></a>") javascript 认为 website.htmlvariable

在您的代码中:

document.write("<b><h3>Chemical Reactions for GROUP 13 :</h3></b><br> < ul type = "disc" >

它期望 "disc"variable

您可以对所有 " 符号进行编码,或者将文本放入 divs 并在您 select 一个选项时显示它们。

还有;使用 document.write 你不能使用 [enter] 来美化你的代码。

你最好的选择是将文本放在单独的 divs 和 showing/hiding 中,只要你点击 see button !

杰伦

Pastebin code

我必须解决的问题;

< br > 转为纯文本:
。将此用于所有 HTML 标签:<br> 不带空格。

if (item === 2) ???? Item 未定义,必须将其更改为 if (g === "2") ;请注意 "2"2

不同

为每个 div 应用了类名 group;每当调用 gr() 时隐藏它们。

祝你好运,杰伦