我想知道是否有人可以帮助我,在我的代码下面无法显示新字段,如果有人可以帮助或指导我会很感激
<!-- // another fields here //-->
<div id="new_field"--></div>
<script type="text/javascript">
var inputs = {
fields: 0,
target: "new_field",
addInput: function() {
if (this.fields != 5) {
this.fields++;
var newElement = document.createElement('div');
newElement.id = this.target + this.fields;
newElement.innerHTML = "<?php if ($emails) { foreach ($emails as $result) { ?><b><?php echo $entry_emails; ?></b><br /><input type='text' name='emails[]' value='<?php echo $result; ?>' size='auto' maxlength='100%' /><?php } } ?>";
document.getElementById(this.target).appendChild(newElement);
} else {
alert("Only 5 fields allowed.");
}
},
};</script>
也许它不会出现因为php代码
newElement.innerHTML = "<?php if ($emails) { foreach ($emails as $result) { ?><b><?php echo $entry_emails; ?></b><br /><input type='text' name='emails[]' value='<?php echo $result; ?' size='auto' maxlength='100%' /><?php } } ?>";
然后我之前使用此代码工作正常
<table id="add_friends">
<!-- // another fields here //-->
<tr>
<td><b><?php echo $entry_email; ?></b></td>
<td>
</td>
</tr>
<?php if ($emails) { foreach ($emails as $result) { ?>
<tr>
<td><b><?php echo $entry_emails; ?></b></td>
<td><input type="text" name="emails[]" value="<?php echo $result; ?>" /></td>
</tr>
<?php } } ?>
</table>
<script type="text/javascript">
function addFriend() {
var tbl = document.getElementById('add_friends');
var iteration = tbl.tBodies[0].rows.length;
newRow = tbl.tBodies[0].insertRow(-1);
var newCell = newRow.insertCell(0);
newCell.innerHTML = 'Entry Your friend email';
var newCell1 = newRow.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'emails[]';
el.size = 30;
el.maxlength = 45;
newCell1.appendChild(el);
}</script>
或者是否有可能将代码更改为底层代码?或者还有其他更好的意见吗?
答案 0 :(得分:1)
您的代码无法正常工作的唯一原因是PHP代码。客户端不在客户端处理PHP,服务器在服务器端处理PHP。