javascript 动态设置input的placeholder值

方法1:通过js来设置文本框input的placeholder值
document.getElementById(“input”).setAttribute(“placeholder”,“新文本内容”);
方法2:通过jquery设置文本框input的placeholder值
$(’#input’).attr(‘placeholder’,‘新文本内容’);

二、
js 下拉框选择改变第二个input对应的值
例如:

var objctSelect=document.getElementById('objctSelect');
var objectName=document.getElementById('objectName');
var objectInput=document.getElementById('objectInput');
objctSelect.addEventListener('change',function(e){
	var event = e || window.event;
	var target = event.currentTarget;
	var index = target.selectedIndex;
	switch(index) {
		case 0:
		  objectName.innerHTML='企业名称';
		  objectInput.setAttribute("placeholder","请输入企业名称");
		break;
		case 1:
		  objectName.innerHTML='车牌号码';
		  objectInput.setAttribute("placeholder","请输入车牌号码");
		break;
		case 2:
		  objectName.innerHTML='姓名';
		  objectInput.setAttribute("placeholder","请输入姓名");
		break;
	}
})

你可能感兴趣的:(js)