输出问题 比如[zhuliao] => 甜玉米 两根 干粉 四匙 白砂糖 适量 输出到这个文本框里面 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 输出到文本框里 那就用ajax 取json 交给js来处理吧 给你段代码,单独运行下,自已分析吧<script>var testData = "甜玉米 两根 干粉 四匙 白砂糖 适量 CCCC DDDD AAAA BBBB";//or from json dataString.prototype.trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); }function fill(){ var arr= new Array(); arr=testData.trim().split(" ");//split var len = arr.length; if(len%2=="0"){//even for(var i=0,j=0;i<len;i++,i++,j++){ var tmpName = getObj("name" ,j); var tmpValue = getObj("value",j); console.log(typeof tmpName); if(tmpName == null){ createElem("name","value",j) tmpName = getObj("name" ,j); tmpValue = getObj("value",j); //continue; } console.log("even required"+arr[i]); tmpName.value = arr[i]; tmpValue.value = arr[i+1]; } }else{ alert("数据不配套啊!"); } return false;}function getObj( base, i){ return document.getElementById(base+i);}function clear2(){ var tt = document.getElementById('content').getElementsByTagName('input'); for(j=0;j<tt.length;j++){ tt[j].value=""; } return false;}function createElem(nm,val,i){ _obj = document.getElementById('content'); _input = document.createElement('input'); //default type text _oText = document.createTextNode(" "); _br = document.createElement('br'); _input.id = nm+i; _obj.appendChild(_input); _obj.appendChild(_oText); _input = document.createElement('input'); _input.id = val+i; _obj.appendChild(_input); _obj.appendChild(_br);}</script><div id="content"></div><input type=button value="Sub" onclick="fill()" /><input type=button value="Clear" onclick="clear2()" /> 用explode()函数将其转换成数组,再循环输入框标签,同时将值填入 sql语句的问题 求助 zend studio里面导入PHP工程,为何运行时什么都不显示啊 cookie的取值 分享IIS下安装php533的体验 求一个滚动查询方法 求一正则表达式! 一个smarty的问题 再次问刷新问题??? The IMAP module does not seem to be installed on this PHP setup, please see NOCC's documentation. [新人求助]onethink二次开发流程 访问应用时的 path与location php 读取超大网页内容
var testData = "甜玉米 两根 干粉 四匙 白砂糖 适量 CCCC DDDD AAAA BBBB";//or from json data
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}function fill(){
var arr= new Array();
arr=testData.trim().split(" ");//split
var len = arr.length;
if(len%2=="0"){//even
for(var i=0,j=0;i<len;i++,i++,j++){
var tmpName = getObj("name" ,j);
var tmpValue = getObj("value",j);
console.log(typeof tmpName);
if(tmpName == null){
createElem("name","value",j)
tmpName = getObj("name" ,j);
tmpValue = getObj("value",j);
//continue;
}
console.log("even required"+arr[i]);
tmpName.value = arr[i];
tmpValue.value = arr[i+1];
}
}else{
alert("数据不配套啊!");
}
return false;
}function getObj( base, i){
return document.getElementById(base+i);
}
function clear2(){
var tt = document.getElementById('content').getElementsByTagName('input');
for(j=0;j<tt.length;j++){
tt[j].value="";
}
return false;
}function createElem(nm,val,i){
_obj = document.getElementById('content');
_input = document.createElement('input'); //default type text
_oText = document.createTextNode(" ");
_br = document.createElement('br');
_input.id = nm+i;
_obj.appendChild(_input);
_obj.appendChild(_oText);
_input = document.createElement('input');
_input.id = val+i;
_obj.appendChild(_input);
_obj.appendChild(_br);
}</script><div id="content"></div><input type=button value="Sub" onclick="fill()" />
<input type=button value="Clear" onclick="clear2()" />