Вы находитесь на странице: 1из 4

<?

php
class sample
{
function show() // methods
{
echo "hello";
}
function add($x,$y)
{
return $x+$y;
}
}

$s=new sample; // class object

$s->show(); // accessing methods

echo $s->add(10,2);

?>
------------------------------------------------------------
<html>
<head>
<title>Dynamic add element</title>
<script>
function check()
{
var div=document.createElement("div");

div.innerHTML="hello friend";

document.body.appendChild(div);

}
</script>
</head>
<body>

<input type="button" onclick="check();" value="Add Paragraph"/>

</body>
</html>

-------------------------------------------
<html>
<head>
<title>Dynamic add element</title>
<script>
function check()
{
var div=document.createElement("div");
div.innerHTML="This is a div ";

var btn=document.createElement("button");
btn.innerHTML="Click Here";

document.getElementById("p1").appendChild(div);
document.getElementById("p1").appendChild(btn);
}
</script>
</head>
<body>

<input type="button" onclick="check();" value="Add Paragraph"/>


<p id="p1" style="border:2px solid red;width:500px;height:300px;"></p>
</body>
</html>

-------------------------------------------
<!-- attributes in javascript -->
<!-- these attribute check the existency of a attribute -->
<!-- attributes are

1. setAttribute("tag-name","value); :- to set new attribute in a tag at


runtime.

2. removeAttribute("tag-name") :- remove attribute at runtime.

3. hasAttribute("tag-name") :- return true or false if attribute exists


than written true otherwise return false.

4. getAttribute("tag-name") :- return string/value in a attribute.

-->
<html>
<head>
<title>My Attribute</title>
<script>
function chkhas()
{

alert(document.getElementById("ins").hasAttribute("value"));

var x=document.getElementById("p1").hasAttribute("style");

if(x==false)
{

document.getElementById("p1").setAttribute("style","color:red");
}
}
function chkremove()
{
document.getElementById("email").removeAttribute("style");
}
function chkget()
{
let
x=document.getElementById("email").getAttribute("value");
alert(x);

if(x=="a@gmail.com")
{

document.getElementById("email").value="ankush@gmail.com";
}
}
function chkset()
{

document.getElementById("p1").setAttribute("style","border:2px solid
red;color:blue;font-size:32px;");
}
</script>
</head>
<body>
<p id="p1">Hello Friends</p>

<input type="text" value="ankush sharma" id="ins" />

<input type="text" style="border:2px solid;" value="a@gmail.com"


id="email" />

<input type="button" onclick="chkhas()" value="hasAttribute" />


<input type="button" onclick="chkremove()" value="removeAttribute" />
<input type="button" onclick="chkget()" value="getAttribute" />
<input type="button" onclick="chkset()" value="setAttribute" />
</body>
</html>
-----------------------------------
<!--
window methods

1. prompt("string","default-value"); :- use for input


2. confrim("string"); :- use for confromation message
3. alert("string");
-->
<script>
let num1=parseInt(prompt("enter the number",10));
let num2=parseInt(prompt("enter the number",20));

let res=num1+num2;

alert("sum is "+res);

</script>
--------------------------------------
<!--
window methods

1. prompt("string","default-value"); :- use for input


2. confrim("string"); :- use for confromation message
3. alert("string");
-->
<script>
let x=confirm("do you want to save a file");

if(x==true)
{
alert("click on ok button");
}
else
{
alert("click on cancel button");
}
</script>
---------------------------------------
<!--
date() :- date is a object method.
:- to hold date and time.
:- date (day,month,year)
:- time(hour,minute,seconds)

d-m-y
dd-mm-yy
d-m-yyyy
yyyy-mm-dd
-->
<script>

let x=new Date();

alert(x);

let y=new Date("01-10-2016");

alert(y);

let z=new Date();

alert(z.getMinutes());
alert(z.getHours());
alert(z.getSeconds());
alert(z.getDay());
alert(z.getMonth());
alert(z.getYear());

z.setHours();
z.setMinutes();
z.setSeonds();
z.setDay();
z.setMonth();
z.setYear();
</script>

Вам также может понравиться