var mydata = null;
var par = [];
var job = [] ;
var customer = [];
var optionObject = {};
var table=document.getElementById('table2'),tr,input,row,cell
var selectPosition = $('#num1').val();
$.post('php/GetJobs.php',{'selectPosition': selectPosition }, function(data) {
mydata = data;
par = JSON.parse(mydata);
for (var i= 0; i <= par.length-1; i++) {
job.push(par[i][0]);
customer.push(par[i][1]);
//optionObject["JobNum"] = job[i];
// optionObject["Customer"] = customer[i];
}
for (var row = 0; row <= 0; row++) {
tr=document.createElement('tr');
tr.setAttribute("class","rows");
tr.id = "AddedRow";
i++;
for(var cell=0; cell<1; cell++){
var field = document.createElement("select");
field.setAttribute("id","jobSelector");
var jobCol=document.createElement('td');
jobCol.id = "row";
for(var i =0; i <= job.length-1; i++){
var option = document.createElement("option");
option.setAttribute("value", "");
option.text = job[i] + ' ' + customer[i];
field.appendChild(option);
//var textNode = document.createTextNode();
//jobCol.appendChild(textNode);
}
//field.setAttribute("option","Select Job");
/* We can run a for loop here to obtain all the options from php call*/
**var projectCol =document.createElement('td');
projectCol.setAttribute("class",'celltimes4');
projectCol.id = "row";
projectCol.appendChild(field);
tr.appendChild(projectCol);
var text = field.options[field.selectedIndex].text;
var regex = new RegExp(text)
var textNode = document.createTextNode(field.options[field.selectedIndex].text);
jobCol.appendChild(textNode);
tr.appendChild(jobCol);
}**
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for(var j =0; j <=6; j++){
var field = document.createElement("input");
field.setAttribute("class","alignRight");
field.setAttribute("type","text");
field.setAttribute("name","hours");
field.setAttribute("value","");
td=document.createElement('td');
td.setAttribute("class",'celltimes4');
td.id = "row" + i;
td.appendChild(field);
tr.appendChild(td);
}
td=document.createElement('td');
td.setAttribute("class",'celltimes4c');
td.id = "row14total";
tr.appendChild(td);
table.appendChild(tr);
}
});
我知道所有這些代碼並不是必需的,但我一直在downvote,因爲我沒有提供完整的工作代碼,即使它真的不適用於因爲我正在做PHP調用和JSON解析。使用正則表達式來查找選擇標記內的字符串html
但是,我的問題在於粗體代碼。所以我試圖實現的是在我的select語句中取出內容,並且只取出作業字符串並在該行的第二秒中使用該字符串。現在我是如何擁有它的,它需要Select語句的全部值並將其放置在第二個單元格內。
所以我試圖使用正則表達式來取出字符串,但我根本無法弄清楚如何操作它。
什麼'option'您試圖解析的格式?您當前的代碼將使用全文作爲模式(而不是搜索的東西)來初始化新的RegExp對象。 –
只是你有'for(var row = 0; row <= 0; row ++){... i ++;','i'在這個範圍內不被使用 – depperm
所以這是我當前的代碼,選項值var text = field.options [field.selectedIndex] .text; \t \t \t \t \t var regexp = new RegExp('((A-Z))','g'); \t \t \t \t \t var result = text.match(regexp); \t \t \t \t \t var textNode = document.createTextNode(result); \t \t \t \t \t jobCol.appendChild(textNode); –