JS基础——属性操作

来源:互联网 发布:外网监控软件 编辑:程序博客网 时间:2024/05/24 07:06
<!doctype html><html><head><meta charset="utf-8"><title>JS属性操作1</title><script>window.onload = function(){var oText = document.getElementById('text1');var oSel = document.getElementById('select1');var oBtn = document.getElementById('btn1');//读操作:获取、找到 【元素.属性名】//alert(oSel.value);//alert(oBtn.value);//写操作:“添加”、替换、修改 【元素.属性名 = 新的值】// 字符串连接// oText.value    oSelect.value// '张三' +  '北京' =>'刘伟北京'// '张三' + '在' + '北京' =>'刘伟在北京'//alert(oText.value + '在' + oSel.value);oBtn.onclick = function(){//oText.value = '123';//oBtn.value = 'button';//oText.value = oSel.value;alert(oText.value + '在' + oSel.value);};};</script></head><body><input id="text1" type="text" /><select id="select1"><option value="北京">北京</option><option value="上海">上海</option><option value="杭州">杭州</option></select><input id="btn1" type="button" value="按钮" /></body></html>

0 0