Jquery表和带重音字符的文本问题
I created a table dynamically with Jquery my variables (in a java array was json_encoded from a php array). After this, my variables are perfect with all the accented characters. So far so good. But as soon I put them in this table the results are bad.
here's the code :
<script>
for (var j = 0; j < 13; j++) {
// labels
if (j==0) {
var tab_B = tab_B + "<tr><th>" + label_array2[j] + "</th><th>" +
label_array2[j+1] + "</th><th>" + label_array2[j+2] + "</th></tr>";
}
// inputs
if ((j>0) && (j<13)) {
var tab_B = tab_B + "<tr><td><input type='text' name='" + input_array2[(j*3)] +
"' maxlength='33' size='33' value='" + label_array2[(j*3)] + "'/></td><td><input type='text' name='" +
input_array2[(j*3)+1] + "' maxlength='5' size='5' value='" + label_array2[(j*3)+1] +
"'/></td><td><input type='text' name='" + input_array2[(j*3)+2] +
"' maxlength='6' size='6' value='" + label_array2[(j*3)+2] + "'/></td></tr>";
}
}
$("#recipetable").html(tab_B);
</script>
then I display the table like this :
<table class="reference" border="1" cellpadding="0" width="100%" id="recipetable"></table>
Some texts are truncated :
example :
Before : Pain d'épices
After : Pain d
Am I missing something ?
我用Jquery我的变量动态创建了一个表(在java数组中是从php数组中json_encoded)。 在此之后,我的变量与所有重音字符完美搭配。 到现在为止还挺好。 但是,一旦我把它们放在这个表中,结果就不好了。 p>
这里是代码: p>
&lt; script&gt;
for (var j = 0; j&lt; 13; j ++){
// labels = n if(j == 0){
var tab_B = tab_B +“&lt; tr&gt;&lt; th&gt;” + label_array2 [j] +“&lt; / th&gt;&lt; th&gt;” +
label_array2 [j + 1] +“&lt; / th&gt;&lt; th&gt;” + label_array2 [j + 2] +“&lt; / th&gt;&lt; / tr&gt;”;
}
//输入
if((j&gt; 0)&amp;&amp;(j&lt; 13)){\ n var tab_B = tab_B +“&lt; tr&gt;&lt; td&gt;&lt; input type ='text'name ='”+ input_array2 [(j * 3)] +
“'maxlength ='33'size = '33 'value ='“+ label_array2 [(j * 3)] +”'/&gt;&lt; / td&gt;&lt; td&gt;&lt; input type ='text'name ='“+
input_array2 [(j * 3 )+ 1] +“'maxlength ='5'size ='5'value ='”+ label_array2 [(j * 3)+1] +
“'/&gt;&lt; / td&gt;&lt; td&gt;&lt; ; input type ='text'name ='“+ input_array2 [(j * 3)+2] +
”'maxlength ='6'mode ='6'value ='“+ label_array2 [(j * 3)+ 2] +“'/&gt;&lt; / td&gt;&lt; / tr&gt;”;
}
}
$(“#recipetable”)。html(tab_B);
&lt; / script&gt; \ n code> pre>
然后我显示如下表格: p>
&lt; table class =“reference”border =“1 “cellpadding =”0“width =”100%“id =”recipetable“&gt;&lt; / table&gt;
code> pre>
某些文字被截断: p>
示例: p>
之前:痛苦之后:痛苦 p>
我错过了什么吗? p>
div>
Truncation comes from not protecting your quotes. It's a simple thing. Now as for the accents, you must know that json requires utf8 encoding. If this doesn't answer the problem, please make a fiddle for us.
Yes, you need to escape your string to avoid the use of quote for javascript.
You have missed escape quote like this,
<input type='text' value='Pain d'épices' maxlength="6" size="6" />
Demo Link http://jsfiddle.net/BB4ka/