Js 可否实现文本框输入值导入单选框,成为单选框的值? <input type="radio" name="fruit" value=""><input type="text" name="others">我想要后面这个文本框提交的值传入到前面的radio值中,而文本框则是由点击radio时出现。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script Language="JavaScript"> function reload(s){ document.all.fruit.value=s; } function reloads(){ alert(document.all.fruit.value); }</script> <input type="radio" name="fruit" value="Pear" onclick="reload(this.value);">Pear<br> <input type="radio" name="fruit" value="orange" onclick="reload(this.value);">orange<br> <input type="radio" name="fruit" > <input type="text" onkeyUp="reload(this.value);"name="others"><br/> <input type="submit" value="submit" onclick="reloads();"> <body><form id="form1" name="form1" method="post" action=""> <input type="radio" name="radiobutton" value="red" />红色 <input name="radiobutton" type="radio" value="green" checked="checked" /> 绿色 <input type="radio" name="radiobutton" value="black" />黑色 <input name="radiobutton" type="radio" onfocus="document.all['text'].style.display='block';" value="other" />其它<input name="text" type="text" onblur="add_radio(this.value)" style="display:none;"/><input type="button" onclick="alert(document.getElementsByTagName('input')[3].value);" value="查看值"/></form></body><script language="javascript">function add_radio(){var obj;obj=document.getElementsByTagName("input");obj[3].value=document.all['text'].value;}</script> <script Language="JavaScript"> function reload(s){document.getElementById("file1").style.display="none"; document.all.fruit.value=s; } //隐藏层 function rel(){ document.getElementById("file1").style.display="block"; }function reloads(){ alert(document.all.fruit.value); }</script> <input type="radio" name="fruit" value="Pear" onclick="reload(this.value);">Pear<br> <input type="radio" name="fruit" value="orange" onclick="reload(this.value);">orange<br> <input type="radio" name="fruit" onclick="rel();"><div id="file1" style="display:none;"><input type="text" onkeyUp="reload(this.value);" name="others"></div> <br/><input type="submit" value="submit" onclick="reloads();"> <!-----随便写的,供LZ参考---------------------><input type="radio" name="fruit" value="Apple"> Apple<br><input type="radio" name="fruit" value="Pear"> Pear<br><input type="radio" name="fruit" value="orange"> orange<br><input id="othersRad" type="radio" name="fruit" value="" onclick="check()"><span id="othersSpan">自定义</span><input id="othersTxt" type="text" name="others" style="display:none;" onkeypress="Txt_onkeypress()"><br><input type="submit" value="submit"><script>function check(){if (document.getElementById("othersRad").checked==true){document.getElementById("othersTxt").style.display="";}}//回车function Txt_onkeypress(){if (event.keyCode==13){document.getElementById("othersSpan").innerText=document.getElementById("othersTxt").value;document.getElementById("othersTxt").style.display="none";}}</script> loveyunwent的可以达到目的,但有个严重的问题就是点击后出现了文本框,但输入文字时候,随便打入一个字母,文本框就会再次隐藏,需要继续点击才可以再出现。也就是说不可以正常的输入完整的文字。为什么呢? <div id="file1" style="display:none;"><input type="text" onkeyUp="reload(this.value);" name="others"></div> 换成<div id="file1" style="display:none;"><input type="text" onblur="reload(this.value);" name="others"></div> 旧好了啊监空的事件不一样 cnchart:请问你的代码里面的[3]是什么意思? Gt7466的代码提交后会多出一个on的字样 这个是改了以后的代码<script Language="JavaScript"> function reload(s,q){ if(q=="w"){ document.getElementById("file").style.display="none"; } document.getElementById("file1").style.display="none"; document.all.fruit.value=s; document.getElementById("dd").innerHTML=s; } //隐藏层 function rel(){ document.getElementById("dd").innerHTML=""; document.getElementById("file").style.display="block"; document.getElementById("file1").style.display="block"; }function reloads(){ alert(document.all.fruit.value); }</script> <input type="radio" name="fruit" value="Pear" onclick="reload(this.value,'w');">Pear<br> <input type="radio" name="fruit" value="orange" onclick="reload(this.value,'w');">orange<br> <input type="radio" name="fruit" onclick="rel();"><div id="file" style="display:none;"><span id="dd"></span></div><div id="file1" style="display:none;"> <input type="text" onblur="reload(this.value,'q');" name="others"></div> <br/><input type="submit" value="submit" onclick="reloads();"> 是指radio"其它",如为2,就是指radio"黑色"看看document.getElementsByTagName的说明吧 <html><head><script type="text/javascript">function dosome(){ var newRadioTxt = document.all.others.value; if ( newRadioTxt == "" ) { return; } var fruit = document.all.fruit; var radio = document.createElement("<input name='"+ "fruit" +"'/>"); //var radio = document.createElement("input"); radio.setAttribute("type","radio"); //radio.setAttribute("name","fruit"); radio.setAttribute("value",newRadioTxt); var txt = document.createTextNode(" "+radio.value); var br = document.createElement("br"); document.all.main.appendChild( radio ); document.all.main.appendChild( txt ); document.all.main.appendChild( br ); document.getElementById("others").value = "";}</script></head><body><div id="main" onclick="document.getElementById('others').style.display='';"> <input type="radio" name="fruit" value="Apple"> Apple<br> <input type="radio" name="fruit" value="Pear"> Pear<br> <input type="radio" name="fruit" value="orange"> orange<br></div><input type="text" name="others" style="display:none" onblur="this.style.display='none';"><br><input type="submit" onclick="dosome();"></body></html> <body><form id="form1" name="form1" method="post" action=""> <input type="radio" name="color" value="red" onclick="disp();"/>红色 <input name="color" type="radio" value="green" onclick="disp();"/> 绿色 <input type="radio" name="color" value="black" onclick="disp();"/>黑色 <input id="other" type="radio" name="color" onclick="document.getElementById('ottxt').style.display='inline'" value="other" />其它<input id="ottxt" name="ipt" type="text" onblur="add_radio(this.value)" style="display:none;"/><input type="button" onclick="alert(document.getElementById('other').value);" value="查看值"/><input type="submit" onclick="ka()" value="查看最后值" /></form></body><script language="javascript">function add_radio(){document.getElementById("other").value=document.getElementById("ottxt").value;}function disp(){ if(document.form1.ipt.style.display=="") {document.form1.ipt.style.display="none"}}function ka(){ for(i=0;i<document.all.color.length;i++){if(document.all.color[i].checked) {var ftt; ftt=document.all.color[i].value; alert(ftt);}}}</script> DOM 是什么? 有什么意义? 阐述DOM文档对象的结构? javascript minibrowser? 关于脏字屏蔽的问题 CSDN左边可以拖动的框架是怎么作的. jquery模式窗口中打开模式窗口 在JS脚本中如何出发某个按钮的事件。 请问如何不刷新将左侧的下拉菜单的值,在右侧的文本框中显示? 多个框架页面,要在其中一个框架的固定位置显示一句话,就像搜狐首页广告,滚动条变动不引起其位置的变动,该如何实现? 高分。 求教怎么在easyUI的扩展编辑器editor里增加参数传递到后台?[急!跪求!] body中onKeyUp事件出错?? 一个我觉得有点科幻的JS注入,望高手解释...
function reload(s){
document.all.fruit.value=s;
}
function reloads(){
alert(document.all.fruit.value);
}
</script> <input type="radio" name="fruit" value="Pear" onclick="reload(this.value);">Pear<br>
<input type="radio" name="fruit" value="orange" onclick="reload(this.value);">orange<br>
<input type="radio" name="fruit" >
<input type="text" onkeyUp="reload(this.value);"name="others"><br/>
<input type="submit" value="submit" onclick="reloads();">
<form id="form1" name="form1" method="post" action="">
<input type="radio" name="radiobutton" value="red" />红色
<input name="radiobutton" type="radio" value="green" checked="checked" />
绿色
<input type="radio" name="radiobutton" value="black" />黑色
<input name="radiobutton" type="radio" onfocus="document.all['text'].style.display='block';" value="other" />其它
<input name="text" type="text" onblur="add_radio(this.value)" style="display:none;"/>
<input type="button" onclick="alert(document.getElementsByTagName('input')[3].value);" value="查看值"/>
</form>
</body>
<script language="javascript">
function add_radio()
{
var obj;
obj=document.getElementsByTagName("input");
obj[3].value=document.all['text'].value;
}
</script>
<script Language="JavaScript"> function reload(s){
document.getElementById("file1").style.display="none";
document.all.fruit.value=s;
}
//隐藏层
function rel(){
document.getElementById("file1").style.display="block";
}
function reloads(){
alert(document.all.fruit.value);
}
</script> <input type="radio" name="fruit" value="Pear" onclick="reload(this.value);">Pear<br>
<input type="radio" name="fruit" value="orange" onclick="reload(this.value);">orange<br>
<input type="radio" name="fruit" onclick="rel();"><div id="file1" style="display:none;"><input type="text" onkeyUp="reload(this.value);" name="others"></div>
<br/>
<input type="submit" value="submit" onclick="reloads();">
<!-----随便写的,供LZ参考--------------------->
<input type="radio" name="fruit" value="Apple">
Apple<br>
<input type="radio" name="fruit" value="Pear">
Pear<br>
<input type="radio" name="fruit" value="orange">
orange<br>
<input id="othersRad" type="radio" name="fruit" value="" onclick="check()"><span id="othersSpan">自定义</span><input id="othersTxt" type="text" name="others" style="display:none;" onkeypress="Txt_onkeypress()"><br>
<input type="submit" value="submit"><script>
function check()
{
if (document.getElementById("othersRad").checked==true)
{document.getElementById("othersTxt").style.display="";}
}//回车
function Txt_onkeypress()
{
if (event.keyCode==13)
{
document.getElementById("othersSpan").innerText=document.getElementById("othersTxt").value;
document.getElementById("othersTxt").style.display="none";
}
}
</script>
点击后出现了文本框,但输入文字时候,随便打入一个字母,文本框就会再次隐藏,需要继续点击才可以再出现。也就是说不可以正常的输入完整的文字。为什么呢?
(this.value);" name="others"></div>
换成
<div id="file1" style="display:none;"><input type="text" onblur="reload
(this.value);" name="others"></div> 旧好了啊
监空的事件不一样
请问你的代码里面的[3]是什么意思?
这个是改了以后的代码<script Language="JavaScript"> function reload(s,q){
if(q=="w"){
document.getElementById("file").style.display="none";
}
document.getElementById("file1").style.display="none";
document.all.fruit.value=s;
document.getElementById("dd").innerHTML=s;
}
//隐藏层
function rel(){
document.getElementById("dd").innerHTML="";
document.getElementById("file").style.display="block";
document.getElementById("file1").style.display="block";
}
function reloads(){
alert(document.all.fruit.value);
}
</script>
<input type="radio" name="fruit" value="Pear" onclick="reload(this.value,'w');">Pear<br>
<input type="radio" name="fruit" value="orange" onclick="reload(this.value,'w');">orange<br>
<input type="radio" name="fruit" onclick="rel();"><div id="file" style="display:none;"><span id="dd"></span></div><div id="file1" style="display:none;">
<input type="text" onblur="reload(this.value,'q');" name="others"></div>
<br/>
<input type="submit" value="submit" onclick="reloads();">
是指radio"其它",如为2,就是指radio"黑色"看看document.getElementsByTagName的说明吧
<html>
<head>
<script type="text/javascript">
function dosome()
{
var newRadioTxt = document.all.others.value;
if ( newRadioTxt == "" )
{
return;
}
var fruit = document.all.fruit;
var radio = document.createElement("<input name='"+ "fruit" +"'/>");
//var radio = document.createElement("input");
radio.setAttribute("type","radio");
//radio.setAttribute("name","fruit");
radio.setAttribute("value",newRadioTxt);
var txt = document.createTextNode(" "+radio.value);
var br = document.createElement("br");
document.all.main.appendChild( radio );
document.all.main.appendChild( txt );
document.all.main.appendChild( br );
document.getElementById("others").value = "";
}
</script>
</head>
<body>
<div id="main" onclick="document.getElementById('others').style.display='';">
<input type="radio" name="fruit" value="Apple">
Apple<br>
<input type="radio" name="fruit" value="Pear">
Pear<br>
<input type="radio" name="fruit" value="orange">
orange<br>
</div>
<input type="text" name="others" style="display:none" onblur="this.style.display='none';">
<br>
<input type="submit" onclick="dosome();">
</body>
</html>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="radio" name="color" value="red" onclick="disp();"/>红色
<input name="color" type="radio" value="green" onclick="disp();"/>
绿色
<input type="radio" name="color" value="black" onclick="disp();"/>黑色
<input id="other" type="radio" name="color" onclick="document.getElementById('ottxt').style.display='inline'" value="other" />其它
<input id="ottxt" name="ipt" type="text" onblur="add_radio(this.value)" style="display:none;"/>
<input type="button" onclick="alert(document.getElementById('other').value);" value="查看值"/>
<input type="submit" onclick="ka()" value="查看最后值" />
</form>
</body>
<script language="javascript">
function add_radio()
{
document.getElementById("other").value=document.getElementById("ottxt").value;
}
function disp()
{
if(document.form1.ipt.style.display=="")
{document.form1.ipt.style.display="none"}
}
function ka()
{
for(i=0;i<document.all.color.length;i++)
{if(document.all.color[i].checked)
{var ftt;
ftt=document.all.color[i].value;
alert(ftt);}
}
}
</script>