js

## json 

```

■json

myObj = {
  "name":"John",
  "age":30,
  "cars": {
    "car1":"Ford",
    "car2":"BMW",
    "car3":"Fiat"
  }
}
myObj.cars.car2 = "Mercedes";

for (i in myObj.cars) {
    x += myObj.cars[i] + "<br>";
}


```

## json array

```

myObj = {
    "name":"John",
    "age":30,
    "cars": [
        {"name":"Ford", "models":["Fiesta", "Focus", "Mustang"]},
        {"name":"BMW", "models":["320", "X3", "X5"]},
        {"name":"Fiat", "models":["500", "Panda"] }
    ]
}
for (i in myObj.cars) {
    x += "<h2>" + myObj.cars[i].name + "</h2>";
    for (j in myObj.cars[i].models) {
        x += myObj.cars[i].models[j] + "<br>";
    }
}
```

## json parse

```
var txt = '{"name":"John", "age":30, "city":"New York"}'
var obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;
```


## json parse date

```
var text = '{"name":"John", "birth":"1986-12-14", "city":"New York"}';
var obj = JSON.parse(text);

```

```
→
John, Sun Dec 14 1986 09:00:00 GMT+0900 (日本標準時)

```



## document cookies


```
function myFunction() {
    document.getElementById("demo").innerHTML =
    "Cookies associated with this document: " + document.cookie;
}

```

```
Cookies associated with this document: _ga=GA1.2.809332990.1539784899; __gads=ID=08a2f3e57dd9fc94:T=1539784904:S=ALNI_MaVAy0epdOz62UDlvOXJfFf1ahtVw; G_ENABLED_IDPS=google; username=ssss; ASPSESSIONIDQSTSCAAQ=PELCHBKDAIOKCOALCBPICMDI; ASPSESSIONIDQQQRACAQ=OIKDPEKDOOJIICHOFPHMCGEG; _gid=GA1.2.1776966801.1540030634; snhbFromEEA=false; ASPSESSIONIDQQQRDABQ=PHDKJPHBBDKMGMBNEMBAFCCJ; ASPSESSIONIDSQSSDAAQ=JPGPBDIBDHHEGGAAOEBHDGOA

```



## document ドメイン取得

```
function myFunction() {
    document.getElementById("demo").innerHTML = document.domain;
}

```
ドメイン
```
www.w3schools.com
```

##  document 最終更新日
```
document.lastModified;
```

## referere  url 

```
function myFunction() {
    document.getElementById("demo").innerHTML = document.referrer;
}

url
 document.URL

```

## document 別タブ開き

```
<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var w = window.open();
    w.document.open();
    w.document.write("<h2>Hello World!</h2>");
    w.document.close();
}
```
##要素を数える

```
function getElements() {
    var x = document.getElementsByName("x");
    document.getElementById("demo").innerHTML = x.length;
}
https://www.w3schools.com/js/tryit.asp?filename=tryjs_doc_getelementsbyname
```
## form 

```

<form name="Form1"></form>
<form name="Form2"></form>
<form name="Form3"></form>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
"The name of the first for is " + document.forms[0].name;
</script>
```

```
The name of the first for is Form1
```

## form disable

```

<form>
<input type="button" id="btn01" value="OK">
</form>

<p>Click the "Disable" button to disable the "OK" button:</p>

<button onclick="disableElement()">Disable</button>

<script>
function disableElement() {
    document.getElementById("btn01").disabled = true;
}
</script>

https://www.w3schools.com/js/tryit.asp?filename=tryjs_button_disabled
```

### form name値取得

```

<form id="frm1" action="/action_page.php">
<button id="btn1" name="subject" type="submit" value="HTML">HTML</button>
</form>

<p>Click the "Try it" button to display the name of the "HTML" button:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("btn1").name;
    document.getElementById("demo").innerHTML = x;
}
```

## form submit formの値をとる

```
<form id="frm1" action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br><br>
  <input type="button" onclick="myFunction()" value="Submit">
</form>

<script>
function myFunction() {
    document.getElementById("frm1").submit();
}
</script>

https://www.w3schools.com/js/tryit.asp?filename=tryjs_form_submit
```

## form .reset();

```
.action

<form id="frm1" action="/action_page.php">
→　https://www.w3schools.com/action_page.php

・.length;
→ 3  ※submit含む　inputの数
<form id="frm1" action="/action_page.php">
  First name: <input type="text" name="fname" value="Donald"><br>
  Last name: <input type="text" name="lname" value="Duck"><br><br>
  <input type="submit" value="Submit">
</form>

・.method;
httpメソッド

<form id="frm1" action="/action_page.php" method="get">

・.name;　name値
→form1
<form id="frm1" name="form1" action="/action_page.php">

・.target;


```

## iframe

srcの中にhtmlをブチ込める

```
<iframe id="myframe" src="/default.asp" height="200" width="250">
<p>Your browser does not support iframes.</p>
</iframe>

```