如图为需要达到效果:radio选中后赋值给多个input
找了个代码但是select,而且打开默认input为空,我想做到radio如果设置选中的话,打开后input默认显示radio的取值以下为参考代码,但不行,劳烦各位给改改看:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title> new document </title>
</head>
<body>
<select id="con_address">
<option value="a|b|c">选项1</option>
<option value="1|2|3">选项2</option>
</select>
<br>
<input type="text" id="h1">
<input type="text" id="h2">
<input type="text" id="h3">
<script>
var a = document.getElementById('con_address'),
b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
]; a.onchange = function(){
var c = this.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
}
</script>
</body>
</html>
找了个代码但是select,而且打开默认input为空,我想做到radio如果设置选中的话,打开后input默认显示radio的取值以下为参考代码,但不行,劳烦各位给改改看:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title> new document </title>
</head>
<body>
<select id="con_address">
<option value="a|b|c">选项1</option>
<option value="1|2|3">选项2</option>
</select>
<br>
<input type="text" id="h1">
<input type="text" id="h2">
<input type="text" id="h3">
<script>
var a = document.getElementById('con_address'),
b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
]; a.onchange = function(){
var c = this.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title> new document </title>
</head>
<body>
<select id="con_address">
<option value="a|b|c" selected>选项1</option>
<option value="1|2|3">选项2</option>
</select>
<br>
<input type="text" id="h1">
<input type="text" id="h2">
<input type="text" id="h3">
<script>
var a = document.getElementById('con_address'),
b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
]; a.onchange = function(){
var c = this.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
};
window.onload = function(){
var c = a.options[a.selectedIndex].value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
}
</script>
</body>
</html>
var c = a.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
}
按钮选中赋值给input框
动手改下不就得了<input name="radioTag" type="radio" value="a|b|c" onclick="changeTxt(this)"/>R选项1
<input name="radioTag" type="radio" value="1|2|3" onclick="changeTxt(this)"/>R选项2 var b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
]; function changeTxt(obj) {
var rv = obj.value.split('|');
for (var i = rv.length; i--; ) {
b[i].value = rv[i];
}
}
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title> new document </title>
<script>
fillFrom = function(obj){
var c = obj.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
} </script>
</head><body>
<input name="con_address" type="radio" value="a|b|c" checked/>选项1
<input name="con_address" type="radio" value="1|2|3"/>选项2
<br>
<input type="text" id="h1">
<input type="text" id="h2">
<input type="text" id="h3">
<script>
var a = document.getElementsByName('con_address'),
b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
]; for (j in a)
{
a[j].onclick = function(){
fillFrom(this);
}
}
window.onload = function(){
for (k in a)
{
if(a[k].defaultChecked) fillFrom(a[k]);
}
}
</script>
</body>
</html
fillFrom = function(obj){
不能这么定义吧??
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title> new document </title>
</head>
<body><input name="con_address" id="con_address" type="radio" value="a|b|c" onclick="changeTxt(this)" />R选项1
<input name="con_address" id="con_address" type="radio" value="1|2|3" onclick="changeTxt(this)" checked/>R选项2
<br>
<input type="text" id="h1">
<input type="text" id="h2">
<input type="text" id="h3">
<script>
var a = document.getElementById('con_address'),
b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
];
window.onload=function(){
var c = a.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
} function changeTxt(obj) {
var rv = obj.value.split('|');
for (var i = rv.length; i--; ) {
b[i].value = rv[i];
}
}
//alert(a.value);
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title> new document </title>
<script>
fillFrom = function(obj){
var c = obj.value.split('|');
for(var i=c.length; i--;){
b[i].value = c[i];
}
} </script>
</head><body>
<input name="con_address" type="radio" value="a|b|c"/>选项1
<input name="con_address" type="radio" value="1|2|3" checked/>选项2
<br>
<input type="text" id="h1">
<input type="text" id="h2">
<input type="text" id="h3">
<script>
var a = document.getElementsByName('con_address'),
b = [
document.getElementById('h1'),
document.getElementById('h2'),
document.getElementById('h3')
]; for (var j=0;j<a.length;j++)
{
a[j].onclick = function(){
fillFrom(this);
}
}
window.onload = function(){
for (var k=0;k<a.length;k++)
{
if(a[k].defaultChecked) fillFrom(a[k]);
}
}
</script>
</body>
</html>
<body><input name="con_address" id="con_address" type="radio" value="a|b|c" onclick="changeTxt(this)" />R选项1
<input name="con_address" id="con_address" type="radio" value="1|2|3" onclick="changeTxt(this)" checked/>R选项2
<br>
页面上的控件ID是唯一的,不能相同