如何将按钮所选择到的值添加到对应行文本框中
jsp:
<input type="text" name="opt" id="opt" value="<%= c %>" maxlength="255">
<input type="button" name="drop" value=" − " onclick="dropOpt(this);">
<input type="button" id="addopt" value=" + " onclick="addOpt(this,'');">
<input type="button" id="select" value=" 选择主题 " onclick="javascript:click1();"">
function click1(){
var url = baseURL+"/oa/vote/view-polls-select.jsp";
var style = "dialogHeight:450px;dialogLeft:300px;dialogTop:200px;dialogWidth:595px;center:yes;resizable:no;status:no;scollbar:no;";
var returnValue=showModalDialog(url,window,style);
if(returnValue==null||returnValue.length<=0)return;
var array = returnValue.split("|"); document.getElementById("opt").value=array[0];
}
function addOptions(b){
if(b.length>0) {
var dr = document.getElementById("addopt");
for(var j = 0; j < b.length; j++) {
if(j>0) {
addOpt(dr,b[j]);
}
}
}
}function dropOpt(btn){
btns = document.getElementsByName('drop');
if(btns.length < 2) return;
if(document.getElementById) {
tr = btn;
while (tr.tagName != 'TR') tr = tr.parentNode;
tr.parentNode.removeChild(tr);
var ma = document.getElementById("max_answers");
var ml = ma.options.length;
ma.options[ml-1] = null;
}
}function addOpt(btn,value){
btns = document.getElementsByName('drop');
if(btns.length > 20) return;
if(document.getElementById) {
tr = btn;
while (tr.tagName != 'TR') tr = tr.parentNode;
var newTr = tr.parentNode.insertBefore(tr.cloneNode(true),tr.nextSibling);
var str;
thisChilds = newTr.getElementsByTagName('td');
for (var i = 0; i < thisChilds.length; i++){
if (thisChilds[i].className == 'options') {
str = '<input type="text" id="opt" name="opt" value="'+value+'" maxlength="255">\n';
str = str + '<input type="button" name="drop" value=" − " onclick="dropOpt(this);">\n';
str = str + '<input type="button" id="addopt" value=" + " onclick="addOpt(this,\'\');">';
str = str + '<input type="button" id="select" value=" 选择主题 " onclick="javascript:click1();"">';
thisChilds[i].innerHTML = str;
}
}
var ma = document.getElementById("max_answers");
var ml = ma.options.length;
ma.options[ml] = new Option(ml+1,ml+1);
}
}
jsp:
<input type="text" name="opt" id="opt" value="<%= c %>" maxlength="255">
<input type="button" name="drop" value=" − " onclick="dropOpt(this);">
<input type="button" id="addopt" value=" + " onclick="addOpt(this,'');">
<input type="button" id="select" value=" 选择主题 " onclick="javascript:click1();"">
function click1(){
var url = baseURL+"/oa/vote/view-polls-select.jsp";
var style = "dialogHeight:450px;dialogLeft:300px;dialogTop:200px;dialogWidth:595px;center:yes;resizable:no;status:no;scollbar:no;";
var returnValue=showModalDialog(url,window,style);
if(returnValue==null||returnValue.length<=0)return;
var array = returnValue.split("|"); document.getElementById("opt").value=array[0];
}
function addOptions(b){
if(b.length>0) {
var dr = document.getElementById("addopt");
for(var j = 0; j < b.length; j++) {
if(j>0) {
addOpt(dr,b[j]);
}
}
}
}function dropOpt(btn){
btns = document.getElementsByName('drop');
if(btns.length < 2) return;
if(document.getElementById) {
tr = btn;
while (tr.tagName != 'TR') tr = tr.parentNode;
tr.parentNode.removeChild(tr);
var ma = document.getElementById("max_answers");
var ml = ma.options.length;
ma.options[ml-1] = null;
}
}function addOpt(btn,value){
btns = document.getElementsByName('drop');
if(btns.length > 20) return;
if(document.getElementById) {
tr = btn;
while (tr.tagName != 'TR') tr = tr.parentNode;
var newTr = tr.parentNode.insertBefore(tr.cloneNode(true),tr.nextSibling);
var str;
thisChilds = newTr.getElementsByTagName('td');
for (var i = 0; i < thisChilds.length; i++){
if (thisChilds[i].className == 'options') {
str = '<input type="text" id="opt" name="opt" value="'+value+'" maxlength="255">\n';
str = str + '<input type="button" name="drop" value=" − " onclick="dropOpt(this);">\n';
str = str + '<input type="button" id="addopt" value=" + " onclick="addOpt(this,\'\');">';
str = str + '<input type="button" id="select" value=" 选择主题 " onclick="javascript:click1();"">';
thisChilds[i].innerHTML = str;
}
}
var ma = document.getElementById("max_answers");
var ml = ma.options.length;
ma.options[ml] = new Option(ml+1,ml+1);
}
}
这句不行?
<input type="button" id="select0" value=" 选择主题 " onclick="javascript:click1('0');"">
function addOpt(btn,value){
btns = document.getElementsByName('drop');
if(btns.length > 20) return;
if(document.getElementById) {
tr = btn;
while (tr.tagName != 'TR') tr = tr.parentNode;
var newTr = tr.parentNode.insertBefore(tr.cloneNode(true),tr.nextSibling);
var str;
thisChilds = newTr.getElementsByTagName('td');
for (var i = 0; i < thisChilds.length; i++){
if (thisChilds[i].className == 'options') {
str = '<input type="text" id="opt"+i+"" name="opt" value="'+value+'" maxlength="255">\n';
str = str + '<input type="button" name="drop" value=" − " onclick="dropOpt(this);">\n';
str = str + '<input type="button" id="addopt" value=" + " onclick="addOpt(this,\'\');">';
str = str + '<input type="button" id="select"+i+"" value=" 选择主题 " onclick="javascript:click1('"+i+"');"">';
thisChilds[i].innerHTML = str;
}
}
var ma = document.getElementById("max_answers");
var ml = ma.options.length;
ma.options[ml] = new Option(ml+1,ml+1);
}
}
function click1(val){
var url = baseURL+"/oa/vote/view-polls-select.jsp";
var style = "dialogHeight:450px;dialogLeft:300px;dialogTop:200px;dialogWidth:595px;center:yes;resizable:no;status:no;scollbar:no;";
var returnValue=showModalDialog(url,window,style);
if(returnValue==null||returnValue.length<=0)return;
var array = returnValue.split("|"); document.getElementById("opt"+val).value=array[0];
}
仔细看红色部分
只是提供一种思路 具体的还要你自己慢慢调试
function addOpt(btn,value){
btns = document.getElementsByName('drop');
if(btns.length > 20) return;
if(document.getElementById) {
tr = btn;
while (tr.tagName != 'TR') tr = tr.parentNode;
var newTr = tr.parentNode.insertBefore(tr.cloneNode(true),tr.nextSibling);
var str;
thisChilds = newTr.getElementsByTagName('td');
for (var i = 0; i < thisChilds.length; i++){
if (thisChilds[i].className == 'options') {
str = '<input type="text" id="opt"+i+"" name="opt" value="'+value+'" maxlength="255">\n';
str = str + '<input type="button" name="drop" value=" − " onclick="dropOpt(this);">\n';
str = str + '<input type="button" id="addopt" value=" + " onclick="addOpt(this,\'\');">';
str = str + '<input type="button" id="select"+i+"" value=" 选择主题 " onclick="javascript:click1('"+i+"');"">';
thisChilds[i].innerHTML = str;
}
}
var ma = document.getElementById("max_answers");
var ml = ma.options.length;
ma.options[ml] = new Option(ml+1,ml+1);
}
}
function click1(val){
var url = baseURL+"/oa/vote/view-polls-select.jsp";
var style = "dialogHeight:450px;dialogLeft:300px;dialogTop:200px;dialogWidth:595px;center:yes;resizable:no;status:no;scollbar:no;";
var returnValue=showModalDialog(url,window,style);
if(returnValue==null||returnValue.length<=0)return;
var array = returnValue.split("|"); document.getElementById("opt"+val).value=array[0];
}