标签:style blog http io color ar java sp for
DOM通过ID或NAME获取值
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>通过ID获取值</title> <script type="text/javascript"> var getname = function () { alert( document.getElementById(‘name‘).value); } var getage = function () { alert(document.getElementById(‘age‘).value); }
<script type="text/javascript">
function givevalue()//用来测验getElementsByTagName();
{
var inputs = document.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++)
{
inputs[i].value = "Nihao";
}
}
</script>
function getname1() { var txt = document.getElementById("name"); alert(txt.value); } function getage1() { alert(document.getElementById(‘age‘).value); } </script> <script type="text/javascript"> function Getelemntbyname() { var rads = document.getElementsByName("gender"); for(var i=0;i<rads.length;i++) { var ra = rads[i]; alert(ra.value); } } </script> </head> <body> <input type="text" id="name" /> <input type="button" value="点击"onclick="getname()"/><br/> <input type="text" id="age" /> <input type="button" value="点击" onclick="getage()"/> <input type="radio" name="gender" value="男"/>男 <input type="radio" name="gender" value="女" />女 <input type="radio" name="gender"value="保密" />保密 <input type="radio" name="gender" value="变异"/>变异 <input type="button" onclick=" Getelemntbyname()" value="click"/> </body> </html>
标签:style blog http io color ar java sp for
原文地址:http://www.cnblogs.com/sytu/p/4085878.html