JavaScript在网页中出现的位置
来源:互联网 发布:学生党淘宝店铺白菜价 编辑:程序博客网 时间:2024/05/16 04:53
这个是需要我们了解的
javascript 操作网页上元素 文档元素 文件对象模型 Document Object Model,简称DOM
alert 警告 就是在我们输入信息的时候 出错弹出的窗口 或者 提示什么的时候弹出的窗口
1.写在网页中
a.直接写在事件名称后面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script language="javascript"></script></head><body><link rel="stylesheet" type="text/css" href="1.css"/><form>输入姓名<input type="text"><input type="button" value="问候" onclick="alert('你好!');"></form></body></html>
b.做成函数写在head中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script language="javascript">function sayHello(){alert("hello !" + document.forms[0].xm.value);} </script></head><body><link rel="stylesheet" type="text/css" href="1.css"/><form>输入姓名<input type="text" name="xm"><input type="button" value="问候" onclick="sayHello()"></form></body></html>
2.存在于单独的js文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="1.js"></script></head><body><form>输入姓名<input type="text" name="xm"><input type="button" value="问候" onclick="sayHello()"></form></body></html>
// JavaScript Documentfunction sayHello(){alert("hello !!!" + document.forms[0].xm.value);}
3.没有表单<form>找元素
通过name
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="1.js"></script></head><body>输入姓名<input type="text" name="xm"><input type="button" value="问候" onclick="sayHello()"></body></html>
// JavaScript Documentfunction sayHello(){alert("你好 !!!" + document.getElementsByName("xm")[0].value);}
通过id
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="1.js"></script></head><body>输入姓名<input type="text" id="xm"><input type="button" value="问候" onclick="sayHello()"></body></html>
// JavaScript Documentfunction sayHello(){alert("你好 !!!" + document.getElementsByName("xm")[0].value);}
0 0
- JavaScript在网页中出现的位置
- [第六季]2.Javascript代码在网页中出现的位置
- JavaScript在网页中的位置
- JavaScript--在网页中调试的方法
- 查询字符在字符串中第几次出现的位置
- 找s2在s1中第一次出现的位置
- js 查找某个值在数组中出现的位置
- 指定数字在数组中第一次出现的位置
- 获取特定字符串在 字符串中出现的所有位置
- 查找一串字母在一个文件中出现的位置
- 字符在字符串中出现的次数和位置
- 在javascript中如何设置textbox的光标的位置
- scrollTop:在JavaScript中获取当前页面的滚动位置
- 在javascript中如何获得textbox输入光标的位置
- 在javascript中如何获得textbox输入光标的位置
- JavaScript 在字符串中替换某个位置的字符
- 在JavaScript数组中找到最小元素的位置
- JavaScript 在字符串中替换某个位置的字符
- EditText使用Selector设置选中与边框颜色
- 找出一个无环单链表里面的倒数第K个元素,时间复杂度为O(n)
- 截取指定字符串
- 较难处理的背包问题+无后效性的深入理解(09年多校)(3008)
- iOS 音频采集 AudioBufferList转CMSampleBufferRef
- JavaScript在网页中出现的位置
- Trie树的Java实现
- struts2 json-plugin 提供跨站访问支持
- Qt5.5.0中文乱码解决
- hdu 1011 Tempter of the Bone【DFS+奇偶性剪枝】
- TextSwitcher结合OnTouchListener实现翻页效果
- 使用基于ThinkPHP3.2.3的ThinkAdmin创建手机电脑通用的表白墙(七)优化:访问控制
- Apache solr和elastic search的比较
- CentOS中安装与配置Tomcat-8方法