1. Trang chủ
  2. » Giáo án - Bài giảng

hoa cuong có thì sử dụng – thích thì lao vào

22 7 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

Ta dùng đặc tính inner và outer để thay đổi nội dung hoặc lấy giá trị của một vùng nào đó trên trang web.. a) Phân biệt giữa inner và outer[r]

(1)

HTML DOM - Forms

(2)

Đối tượng form

Form thành phần dùng để thu thập liệu,

thông tin từ người dùng Mỗi phần tử form

một đối tượng DOM Do phần tử

form có kiện phương thức

(3)(4)(5)(6)

Phần tử Tên kiện

Button onClick

Checkbox onClick

Form OnSubmit, onReset

Textbox OnBlur,OnChange,OnFocus,Onselect

Radio OnClick

Reset button OnClick

Dropdown menu OnBlur,onChange,onFocus,onSelect

Submit button OnClick

(7)

T/tính Mơ tả Ví dụ Action Trả đường dẫn

(URL) đến tập tin xử lý form thứ i

Document.forms[i].action

Length Trả số form trang web

Hoặc trả số phần tử form thứ i

Countform=document.forms.length Countfield=document.forms[i].length

Name Trả giá trị tên

form thứ i Nameform=document.forms[i].name

Method Các định phương thức

của form thứ i Methodform=document.forms[i].method

elements mảng element chứa

(8)

Ví dụ:

<script>

function kq()

{

sptform=document.

form1.

length

document.

form1.spt.value

=sptform

tenform=document.

forms[0].

name

document.form1.

formname.value

=tenform

}

(9)

1.

Các thuộc tính mảng element

T/ tính Mơ tả Ví dụ

name Xác định tên phần

tử j form thứ i document.forms[i].elements[j].name

type Xác định lọai đối

tượng document.forms[i].elements[j].type

value Xác định giá trị phần

(10)

checked Xác định phần tử thứ j

có checked khơng document.form[i].elements[j].checked

trả giá trị true false disabled Thiết lập chế độ vơ hiệu

hóa đối tượng document.form[i].elements[j].disabled

isDisable Kiểm tra phần tử có bị

vơ hiệu hóa hay không document.form[i].elements[j].isDisable

readOnly Cho phép/không thay đổi nội dung phần tử

(11)

Ví dụ:

function

loadform()

{

document.form1.

ok.disabled=true

;

}

function

validateform()

{

a=document.form1.user.value;

if(a != "")

document.form1.

ok.disabled=false

;

else

(12)

Thao tác với phần tử from

(13)

Ví dụ:

<form name=form1>

Please enter the following details:

<p>Name:<br>

<input type=”text” name=txtName

onchange=”txtName_onchange()”

>

<br> Age:<br>

<input type=”text” name=txtAge

onblur=”txtAge_onblur()”

size=3 maxlength=3>

<br>

<input type=”button” value=”Check Details”

name=butCheckForm

(14)

function butCheckForm_onclick()

{

var myForm = document.form1;

if (myForm.txtAge.value == “” || myForm.txtName.value == “”)

{

alert(“Please complete all the form”);

if (myForm.txtName.value == “”)

(15)

else

{

alert(“Thanks for completing the form “ + myForm.txtName.value);

}

}

function txtAge_onblur()

{

var txtAge = document.form1.txtAge;

if (isNaN(txtAge.value) == true)

{

alert(“Please enter a valid age”);

txtAge.focus();

txtAge.select();

}

(16)

Thao tác với phần tử form

1

Xem bảng phụ lục để biết thêm chi tiết thuộc

tính, phương thức, kiện tiêu biểu đối

tượng.

(17)

THAY ĐỔI NỘI DUNG ĐỘNG TRÊN TRANG

Thay đổi nội dung trang dựa vào inner

outer

Ta dùng đặc tính inner outer để thay đổi nội dung

hoặc lấy giá trị vùng trang web.

a)

Phân biệt inner outer

Inner

nội dung chứa bên đối

tượng chứa ID Inner gồm có

InnerHTML lấy nội dung text tag HTML

bên đối tượng ID

(18)

Outer phần inner thân đối tượng

chứa ID Outer gồm có

outerHTML lấy nội dung text tag

HTML đối tượng ID

outerText : lấy nội dung text

Ví dụ:

<Div ID=Intro>

Monitor<B> SAMSUNG</B>

</Div>

(19)

Ví dụ

:

Var s1,s2

s1=Intro.outerText

s2=Intro.innerText

thì s1 s2 nhận giá trị Monitor SAMSUNG

Ví dụ

s1=Intro.outerHTML

s2=Intro.innerHTML

Thì s1=<Div Id=Intro>Monitor<B> SAMSUNG</B></

Div>

(20)(21)

<script>

function

chonsp()

{

prod=document.form1.masp.value;

hinhsp=document.forms[0].hinh.options[document.

forms[0].hinh.selectedIndex].text;

price=document.form1.giasp.value;

ma.innerText=prod;

hinh.innerText=hinhsp;

gia.innerText=price

(22)

function

ChangeImage(path)

{

h.innerHTML="<img src= /images/" + path +"

width=100 height=100 >"

}

Gọi hàm ChangeImage(value)

Ngày đăng: 27/04/2021, 18:27

TỪ KHÓA LIÊN QUAN

w