document.getElementById("元素的id")是前端开发中最有用的方法之一,是面向对象的体现。其能获取指定id的HTML元素,是Javascript的重要方法。
例如,它能实现对某HTML元素中的值进行修改,或者实现讲Javascript中的变量值传递到HTML表单中,再提交到服务器端的Java或PHP当中,实现前端Javascript变量与后台的Java或PHP变量间的间接传递。
【代码】--按按钮,获取IC的值。
<script language = 'javascript'>
function changeValue(){
var obj = document.getElementById("IC")
obj.value = "高通移动芯片-snapdragon msm8255"
}
</script>
<input type = "button" value = "点击我获取芯片值" id="IC" name = "IC" onclick = "changeValue()" />
再例
【代码】--控制SELECT标签所选项和只读功能:
document.getElementById("某SELECT标签id").value = 某option中的值
document.getElementById("某SELECT标签id").disabled = true(或者false)
这个功能可以应用在某些表单修改中,不允许用户修改原来已经填写好的部分资料。
分享到:
相关推荐
javascript:document.getElementById('downLoad').action='/download.php?fileid=15775884';downishare('0');javascript:document.getElementById('downLoad').action='/download.php?fileid=15775884';downishare('...
document.getElementById()对象和使用方法
23.弹出输入提示框:window.prompt(); 24.指定当前显示链接的位置:window.location.href= "URL " 25.取出窗体中的所有表单的...29.得到元素的方法:document.getElementById() 30.设置表单中所有文本型的成员的值为空:
主要是对各浏览器对document.getElementById等方法的实现差异进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助
IE方法:document.frames[‘myFrame’].document.getElementById(‘test’).value; 火狐方法:document.getElementById(‘myFrame’).contentWindow.document.getElementById(‘test’).value; IE、火狐方法: 代码...
利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位。 方法一: document.getElementById("EleId").style.visibility=...
document.getElementById(vImgs).innerHTML="<span style=color:red;font-size:12px>"+16+"</span>"; } else{ document.getElementById(vImgs).innerHTML="<span style=color:red;font-size:12px>"+(16...
5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或value) 6.一个小写转大写的JS: document.getElementById( "output ").value = document.getElementById( "input ").value....
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或&#118alue) 6.一个小写转大写的&#106s: document.getElementById("output").&#118alue = document.getElementById("input").&...
1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是: document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是: window->(navigator,screen,history,location,document) 5.得到表单中...
1.输出语句:document.write("") 2.JS中的注释为:// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document) 5.得到表单中元素的...
5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或value) 6.一个小写转大写的JS: document.getElementById( "output ").value = document.getElementById( "input ").value....
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID號").name(或value) 6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase...
29.得到元素的方法:document.getElementById() 30.设置表单中所有文本型的成员的值为空: var form = window.document.forms[0] for (var i = 0; i<form.elements.length;i ){ if (form.elements.type == "text"){ ...
<script type=text/javascript> function setTab03Syn ( i ) { selectTab03Syn(i); } function selectTab03Syn ( i ) { switch(i){ case 1: document.getElementById("TabTab03Con1").style....
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value) 6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase...
el: document.getElementById('inner-content'), scrollBar: document.getElementById('tool-bar') }) 比较复杂的例子: iScroll.init({ el: document.getElementById('inner-content2'), direction: 'left...