📄 setvote.js
字号:
if (window.Event){ // 修正Event的DOM
Event.prototype.__defineSetter__( " returnValue " , function (b){ //
if ( ! b) this .preventDefault();
return b;
});
}
if (window.Node){
Node.prototype.replaceNode = function (Node){ // 替换指定节点
this .parentNode.replaceChild(Node, this );
}
Node.prototype.removeNode = function (removeChildren){ // 删除指定节点
if (removeChildren)
return this .parentNode.removeChild( this );
else {
var range = document.createRange();
range.selectNodeContents( this );
return this .parentNode.replaceChild(range.extractContents(), this );
}
}
}
var getNameList = function(strName){return document.getElementsByName(strName);}
function checkvotetype(opobj,opmax)
{
var s = opobj.options[opobj.selectedIndex];
var str="您确定您的投票类型是:"+s.text+"吗?确定以后将不可更改!点击取消重新选择。";
var stext=s.text;
var svalue=s.value;
if(confirm(str))
{
document.getElementById("votetype").value=svalue;
opobj.disabled="disabled";
votetypeset(opobj,opmax,stext,svalue);
}
else
return;
}
function ResetVoteType()
{
if(confirm("重新设置将清空当前表单!确认重置吗?"))
{
var str="<ol id=\"votetitles\"></ol>";
document.getElementById("voteset_add").innerHTML="";
document.getElementById("voteset_function").innerHTML=str;
document.getElementById("votetype_select").disabled="";
if (window.clipboardData)
{
window.clipboardData.setData("Text", "<ol id=\"votetitles\"></ol>");
}
return;
}
else
{
return ;
}
}
//投票设置事件
//opmax 限制数
var voten = 0;
function votetypeset(opobj,opmax,stext,svalue){
//vote_set
//hidden Textea ID:vote
//var s = opobj.options[opobj.selectedIndex];
var div_voteset = document.getElementById("voteset_div");
if (!div_voteset){return ;}
document.getElementById("voteset_legend").innerHTML =stext;
//voteset_function
var voteset_add = document.getElementById("voteset_add");
//添加投票项表单
voteset_add.innerHTML = voteset_input(svalue,opmax);
voteset_todata("vote","set_vote",svalue);
}
function voteset_input(s,opmax){
var _inputHmtl = '<input type="text" name="set_votetitle" id="set_votetitle" value="请输入该项标题" onfocus="if(this.value==\'请输入该项标题\') this.value=\'\'" onblur="if(this.value==\'\') this.value=\'请输入该项标题\';" size="80"/>';
_inputHmtl +=' <input type="button" name="put_vset" value="添加" onclick="voteadd_input('+s+',\'set_votetitle\','+opmax+');"/>';
//_inputHmtl +=' <br/><ol id="votetitles"></ol>';
return ("添加项目:" + _inputHmtl);
}
function voteadd_input(s,objid,opmax)
{
var titleobj = document.getElementById(objid);
var voteset_function = document.getElementById("votetitles");
if (!titleobj){return ;}
if(titleobj.value=='请输入该项标题'){alert("请填写相应的内容!");return;}
if (titleobj.value==''){alert("请填写相应的内容 !");return ;}
if (document.getElementsByName("set_vote")){
if (document.getElementsByName("set_vote").length>=parseInt(opmax)){
alert("投票数目超出限制!");
return ;
}
}
voten = voten + 1;
var child_Html = "";
child_Html = '<li id="set_vote_'+voten+'">';
child_Html += '投票项目:<input type="text" name="set_vote" id="set_vote" value="'+titleobj.value+'" onBlur="voteset_todata(\'vote\',\'set_vote\','+s+');" size="80"/> <input type="button" name="del_vset" value="删除" onclick="votedel_input(\'set_vote_'+voten+'\','+s+');"/>';
//问卷调查增加填写表单
if (s=='2')
{
child_Html += ' <br/>子项数:<input maxlength="2" onkeyup="votechild_input('+voten+','+s+');" name="vote_childs_'+voten+'" id="vote_childs_'+voten+'" type="text" value="4" size="1"/>';
child_Html += ' 类型:<select id="vote_childtype_'+voten+'" name="vote_childtype_'+voten+'" onchange="votechild_input('+voten+','+s+');"><option value="0">单选</option><option value="1">多选</option><option value="2">文本</option></select>';
child_Html += ' <input type="hidden" name="voten" id="voten" value="'+voten+'"/><input type="button" name="add_vsetchild" value="添加子项" onclick="votechild_input('+voten+','+s+');"/>';
child_Html += ' <ol type="A" id="vchild_ol_'+voten+'"></ol>'
}
else //非问卷调查表单
{
child_Html += '<br/>子项数:<input maxlength="2" onkeyup="votechild_input('+voten+','+s+');" name="vote_childs_'+voten+'" id="vote_childs_'+voten+'" type="text" value="2" size="1" />';
child_Html += ' <input type="hidden" name="voten" id="voten" value="'+voten+'"/><input type="button" name="add_vsetchild" value="添加子项" onclick="votechild_input('+voten+','+s+');"/>';
child_Html += '<ol type="A" id="vchild_ol_'+voten+'"></ol>';
}
child_Html += '</li>';
voteset_function.innerHTML += child_Html;
voteset_todata("vote","set_vote",s);
}
function votechild_input(objid,s)
{
var child_ol = document.getElementById("vchild_ol_"+objid);
var child_Html = "";
var AddChilds = document.getElementById("vote_childs_"+objid);
//var ChildsType = document.getElementById("vote_childtype_"+objid);
if (isNaN(AddChilds.value))
{
AddChilds.value = 4;
}
//if (ChildsType.options[ChildsType.selectedIndex].value=='2'){AddChilds.value=1;}
AddChilds.value = parseInt(AddChilds.value);
var AddLength = parseInt(AddChilds.value);
if (child_ol)
{
if(s=='2') //问卷调查时
{
var ChildsType = document.getElementById("vote_childtype_"+objid);
if (ChildsType.options[ChildsType.selectedIndex].value=='2'){AddChilds.value=1;} //文本时没有选项
AddChilds.value = parseInt(AddChilds.value);
var AddLength = parseInt(AddChilds.value);
for(var i=1; i<=AddLength; i++)
{
child_Html +='<li id="vchild_li_'+objid+'">';
if (ChildsType.options[ChildsType.selectedIndex].value=='2')
{
child_Html +='答案:<textarea id="vchild_input_'+objid+'" name="vchild_input_'+objid+'" onBlur="if (this.value==\'\'){this.value=\'null\';};voteset_todata(\'vote\',\'set_vote\','+s+');" style="width:460px;height:50px;">null</textarea>';
child_Html +='<input type="hidden" name="vchild_ep_'+objid+'" id="vchild_ep_'+objid+'" value="0"/>';
}
else
{
switch (ChildsType.options[ChildsType.selectedIndex].value)
{
case '0':
child_Html +='<input type="radio" name=""/>';
break;
case '1':
child_Html +='<input type="checkbox" name=""/>';
break;
}
child_Html +='<input type="text" id="vchild_input_'+objid+'" name="vchild_input_'+objid+'" onblur="voteset_todata(\'vote\',\'set_vote\','+s+');" value="请录入该项内容,否则将由默认值替代" onfocus="if(this.value==\'请录入该项内容,否则将由默认值替代\') this.value=\'\'" size="80"/> 得分:<input type="text" name="vchild_ep_'+objid+'" id="vchild_ep_'+objid+'" value="0" onBlur="voteset_todata(\'vote\',\'set_vote\','+s+');" size="3"/>';
}
child_Html +='</li>';
}
}
else if(s=='0') //单选投票时
{
for(var i=1;i<=AddLength;i++)
{
child_Html +='<li id="vchild_li_'+objid+'">';
child_Html +='<input type="radio" name=""/>';
child_Html +='<input type="text" id="vchild_input_'+objid+'" name="vchild_input_'+objid+'" onblur="voteset_todata(\'vote\',\'set_vote\','+s+');" value="请录入该项内容,否则将由默认值替代" onfocus="if(this.value==\'请录入该项内容,否则将由默认值替代\') this.value=\'\'" size="80"/>'
child_Html+=' <input type="hidden" name="vchild_ep_'+objid+'" id="vchild_ep_'+objid+'" value="0"/>'
child_Html+='</li>';
}
}
else //多选 投票时
{
for(var i=1;i<=AddLength;i++)
{
child_Html+='<li id="vchild_li_'+objid+'">';
child_Html+='<input type="checkbox" name=""/>';
child_Html +='<input type="text" id="vchild_input_'+objid+'" name="vchild_input_'+objid+'" onblur="voteset_todata(\'vote\',\'set_vote\','+s+');" value="请录入该项内容,否则将由默认值替代" onfocus="if(this.value==\'请录入该项内容,否则将由默认值替代\') this.value=\'\'" size="80"/> ';
child_Html+='<input type="hidden" name="vchild_ep_'+objid+'" id="vchild_ep_'+objid+'" value="0"/>';
child_Html+='</li>';
}
}
child_ol.innerHTML=child_Html;
}
voteset_todata("vote","set_vote",s);
}
function voteset_todata(objid,valobjid,s)
{
var votedb_Obj = document.getElementById(objid); //隐藏表单vote,用来存储表单项
var voteval_Obj = getNameList(valobjid); //获取每项项目的标题?,即获取多个set_vote投票项目
var voten = getNameList("voten");
votedb_Obj.value = ""; //每次都清空重新填写?
for(var i=0; i<voteval_Obj.length; i++) //共有多少个投票项
{
//start存储标题
voteval_Obj[i].value = voteval_Obj[i].value.replace(/@@|\$\$|\|\$|\@/g,'');
if(voteval_Obj[i].value!='')
{
votedb_Obj.value += voteval_Obj[i].value.replace(/\r/g,'');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -