javascript函数未捕获空格 [英] White Spaces not being captured in javascript function
本文介绍了javascript函数未捕获空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用javascript函数将新行动态添加到html表中.
我正在尝试填充每一行中每个文本的值,同时这样做,我能够添加包含单个单词的数据,但是如果我有诸如姓氏,中间名之类的内容,则仅显示第一个单词...
有人可以建议我需要在函数中进行哪些修改,以使整个字符串由空格分隔吗?
请检查以下代码段.
Hi,
I am trying to add a new row dynamically to a html table using a javascript function.
I am trying to populate the value for each text in each row and while doing so,I am able to add the data which has single words but if I have something like Last Name, Middle Name only the first word is being displayed ...
Can anyone suggest me what I need to modify in the function to get the whole string separated by white spaces?
Please check the below code snippet .
function addRow(tbl_name) {
var tbody = document.getElementById(tbl_name).getElementsByTagName("TBODY")[0];
// create row
var row = document.createElement("TR");
// create table cell 1
var td1 = document.createElement("TD")
// var abc=GetInnerText("lsTest");
var abc="Last Name";
var strHtml1 = "<center><input id="\"Text1\"" type="\"text\"" name=" + getName + " size="\"5\"" value=" + abc + " style="\"background-color:#E2E6C8;margin:0;\"" readonly=""> </input></center>";
td1.innerHTML = strHtml1.replace(/!count!/g, count);
// create table cell 2
var td2 = document.createElement("TD")
var getValue = GetInnerText("Select1");
var getName = "txtBox" + count;
var strHtml2 = "<center><input id="\"Text1\"" type="\"text\"" name=" + getName + " size="\"5\"" value=" + getValue + " style="\"background-color:#E2E6C8;margin:0;\"" readonly=""> </input></center>";
td2.innerHTML = strHtml2.replace(/!count!/g, count);
// create table cell 3
var td3 = document.createElement("TD")
var strHtml3 = "<input type="\"text\"" name="\"in_name\"" value="\"agagag\"" size="\"5\"" maxlength="\"5\"" style="\"height:24;border:" 1="" mode="hold" /> td3.innerHTML = strHtml3.replace(/!count!/g, count);
// append data to row
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
// add to count variable
count = parseInt(count) + 1;
// append row to table
tbody.appendChild(row);
}
推荐答案
您在value(value = Last Name)中缺少引号.这就是为什么只有第一个单词被识别的原因.它应该是value ="Last Name "
如下更改标记
value = \" + abc +"\"
这将起作用.
You are missing quotes in the value(value=Last Name).Thats why only first word is getting recognized.It should be value="Last Name"
Change the markup as below
value=\"" + abc + "\"
This will work.
这篇关于javascript函数未捕获空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文