duanpuchun5275 2013-05-24 06:53
浏览 42
已采纳

Javascript onClick clear在php echo中不起作用

Here is code without php echo and it works.

<tr id='row1'>
<td><input type="text" name="date_day[]" id="date_day1" class="row_changed1"size="1"></td>
<td>
<a href="javascript://" onClick="clearChildren(document.getElementById('row1'))">Clear</a>
</td>
</tr>

But I must use the same in php echo

Tried this

 echo "<tr id='row11'>

 <td>
 <input type='text' name='date_day[]' id='date_day1' class='row_changed1' value='" .$post_date_day. "' size='1'>
 </td>

 <td>
 <input type='text' name='entry_id[]' id='entry_id1' class='row_changed1' size='5' value='".$post_entry_id ."' >
 </td>

 <td>
 <input type='text' name='row_id[]' id='row_id1' value='" .$post_row_id ."' size='1'>
 </td>

 <td>
 <a href=\"javascript://\" onClick=\"clearChildren(document.getElementById('row11'))\">Clear</a>

 </td>

 </tr>";

But does not clear. Possibly because of incorrect usage of ' and " but can not understand what is correct way. Experimented changing ' to " and vice versa, but without success.

clearChildren function

function clearChildren(element) {
for (var i = 0; i < element.childNodes.length; i++) {
var e = element.childNodes[i];
if (e.tagName) switch (e.tagName.toLowerCase()) {
case 'input':
switch (e.type) {
case "radio":
case "checkbox": e.checked = false; break;
case "button":
case "submit":
case "image": break;
default: e.value = ''; break;
}
break;
case 'textarea': e.value = ''; break;
case 'select': e.selectedIndex = -1; break;
default: clearChildren(e);
}
}
}

And view source (selected) is this

input name="date_day[]" id="date_day1" class="row_changed1" value="" size="1" type="text">

<input name="entry_id[]" id="entry_id1" class="row_changed1" size="5" value="24/1305" type="text">

<input name="row_id[]" id="row_id1" value="24" size="1" type="text">

<a href="javascript://" onclick="clearChildren(document.getElementById('row11'))">Clear</a>
  • 写回答

5条回答 默认 最新

  • drbz99867 2013-05-24 07:17
    关注
    echo "<table><tr id='row11'>
    
     <td>
     <input type='text' name='date_day[]' id='date_day1' class='row_changed1' value='' size='1'>
     </td>
    
     <td>
     <input type='text' name='entry_id[]' id='entry_id1' class='row_changed1' size='5' value='' >
     </td>
    
     <td>
     <input type='text' name='row_id[]' id='row_id1' value='' size='1'>
     </td>
    
     <td>
     <a href=\"javascript://\" onClick=\"clearChildren(document.getElementById('row11'));\">Clear</a>
    
     </td>
    
     </tr></table>";
    

    Try this. I think this issue came up due to not proper table structure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记