16 Qi second training job

The first question: completion of City three linkage (including Hunan), with code and renderings.

<! DOCTYPE the HTML>
<HTML>
<head>
</ head>
<body>
<SELECT ID = "Province">
<Option value = "-. 1"> select </ Option>
</ SELECT>
<SELECT ID = " City "> </ SELECT>
<SELECT ID =" Country "> </ SELECT>
<Script type =" text / JavaScript ">
var provinceArr = [" Shanghai "," Jiangsu ',' Hebei '];
var cityArr = [
[ 'Shanghai'],
[ 'Suzhou city', 'Nanjing', 'Yangzhou'],
[ 'Shijiazhuang', 'Qinhuangdao', 'Changgiakou']
];
var countryArr = [
[
[ 'Huangpu region', 'Jing area', 'Changning', 'Pudong']
],
[
[ 'Huqiu', 'Wu area', 'city phase', 'Suzhou area', 'region Wujiang'], [ 'Xuanwu', 'Qinhuai area', 'Jianye', 'Drum region' 'pukou'], [ 'Hanjiang', 'Guangling', 'region jiangdu']
],
[
[ 'Chang'an', 'west region', 'Xinhua area', 'well cut the throat mine'], [ 'harbor area', 'region Shanhaiguan', 'Beidaihe area', 'region funing'], [ 'east area ',' west region ',' Xuanhua area ',' lower garden area ']
]
];
function createOption (obj, Data) {
for (var I in Data) {
var OP = new new Option-(Data [I], I );
obj.options.add (OP);
}
}
var Province = document.getElementById ( 'Province');
createOption (Province, provinceArr);
var = document.getElementById City ( 'City');
province.onchange = function ( ) {
city.options.length = 0;
createOption (City, cityArr [province.value]);
};
var Country = document.getElementById ( 'Country');
city.onchange = function () {
Country.options.length = 0;
createOption(country,countryArr[province.value][city.value]);
};
province.onchange = function(){
city.options.length = 0;
createOption(city,cityArr[province.value]);
if(province.value>=0){
city.onchange();
}
else{
country.options.length = 0;
}
};
</script>
</body>
</html>

 

The second question: removal array arr ([1,2,3,4,2,5,6,2,7,2]) are equal to the elements 2, and generate a new array, does not change the original array.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
var arr = [1,2,3,4,2,5,6,2,7,2];
document.write("原数组:<br/>" + arr);
var a= arr.slice(3,4);
var b = arr.slice(0,1);
var c = arr.slice(2,3);
var d = arr.slice(5,6);
var e = arr.slice(6,7);
var f = arr.slice(8,9);
str = b.concat(c,a,d,e,f);
document.write("<br/>");
document.write("新数组:<br/>" + str);
document.write("<br/>");
document.write("原数组arr:<br/>" + arr);
</script> 
</body>
</html>

Third question: write a function to achieve click the change button to add a red double border to the div element.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style type="text/css">
        div{
            font-family: "Helvetica Neue",Helvetica,Arial,"Microsoft Yahei",sans-serif;
            width: 600px;
            text-align: center;
        }
        .haha{
            margin-top: 20px;
            margin-left: 250px;
            font-size: 20px;
        }
        .haha:hover{
            border: 3px solid purple;
        }
    </style>
</head>
<body>
   <div id="joy">    </ div>
      <The p-> do what you want to do </ the p->

   <button class="haha" onclick="myFunction()">change</button>
   <script type="text/javascript">
    function  myFunction(){
        var Color = document.getElementById("joy");
        Color.style.border = "3px double red";
        Color.innerHTML = "<p>加油!</p>";
       
    }
    </script>
</body>
</html>
 
 
Experience: The more training to help students is by and was able to complete the book, there have been run error and so periods. I have a lot in learning deficiencies places, we wanted more effort, to lay a solid foundation.

 

 

Guess you like

Origin www.cnblogs.com/sltel/p/11688641.html