Javascript 检测用户编辑时的表格单元格更改
我试图检测用户输入的html表格单元格的变化。当我点击表格单元格时,我可以在其中输入文本,但我的.change功能不会被触发。但是,当从数据库填充数据时,在页面加载时,会触发每个表单元格的更改更改函数。我不明白为什么。你能帮忙吗。 我的代码如下:Javascript 检测用户编辑时的表格单元格更改,javascript,jquery,html,django,Javascript,Jquery,Html,Django,我试图检测用户输入的html表格单元格的变化。当我点击表格单元格时,我可以在其中输入文本,但我的.change功能不会被触发。但是,当从数据库填充数据时,在页面加载时,会触发每个表单元格的更改更改函数。我不明白为什么。你能帮忙吗。 我的代码如下: <div id="table" class="table-editable"> <table id="myTable" style="width:100%" class="table">
<div id="table" class="table-editable">
<table id="myTable" style="width:100%" class="table">
<tr>
<th>Id</th>
<th>Link</th>
<th>Naslov</th>
<th>Lokacija</th>
<th>Cijena</th>
<th>Telefon</th>
<th>Posjet</th>
<th>Opis</th>
<th>Prednosti</th>
<th>Nedostaci</th>
<th>Slike</th>
<th>Select</th>
{% for entry in entries %}
</tr>
<tr>
<td>{{ forloop.counter }}</td>
<td><a id="linkHouse_{{ forloop.counter }}" href="{{ entry.link }}">Link na oglas</a></td>
<td contenteditable="true">{{ entry.header }}</td>
<td contenteditable="true">{{ entry.location }}</td>
<td id="priceHouse_{{ forloop.counter }}" contenteditable="true">{{ entry.price }}</td>
<td id="contactHouse_{{ forloop.counter }}" contenteditable="true">{{ entry.contacts }}</td>
<td id="visitedHouse_{{ forloop.counter }}" contenteditable="true">{{ entry.visited }}</td>
<td id="descriptionHouse_{{ forloop.counter }}" contenteditable="true">{% for line in entry.description.splitlines %} {{line}}<br> {% endfor %}</td>
<td id="prosHouse_{{ forloop.counter }}" contenteditable="true" >{% for line in entry.pros.splitlines %} {{line}}<br> {% endfor %}</td>
<td id="consHouse_{{ forloop.counter }}"contenteditable="true">{% for line in entry.cons.splitlines %} {{line}}<br> {% endfor %}</td>
<td >
<a class="fancybox" target="_blank" data-fancybox="images" href="{% static "Pic/img_fjords_wide.jpg" %}"><img src="{% static "Pic/img_fjords_wide.jpg" %}" alt="" style="width:150px"></a>
<a class="hide fancybox" target="_blank" data-fancybox="images" href="{% static "Pic/img_lights_wide.jpg" %}"><img src="{% static "Pic/img_lights_wide.jpg" %}" alt=""></a>
<a class="hide fancybox" target="_blank" data-fancybox="images" href="{% static "Pic/img_mountains_wide.jpg" %}"><img src="{% static "Pic/img_mountains_wide.jpg" %}" alt=""></a>
</td>
<td style="text-align: center; vertical-align: middle;">
<button id="delHouse_{{ forloop.counter }}" onclick="delHouse(this.id)">Delete</button>
<!--<input type="checkbox" name="delete{{ forloop.counter }}">-->
</td>
</tr>
{% endfor %}
</table>
</div>
$(document).ready(function(){
$( "#myTable td" )
.change(function () {
console.log("petar");
var data = this.innerHTML;
console.log("value="+data);
})
.change();
身份证件
链接
纳斯洛夫
洛卡西亚
齐耶纳
电传
波斯杰特
奥皮斯
预言家
内多斯塔奇
斯莱克
挑选
{entries%%中的条目的百分比}
{{forloop.counter}}
{{entry.header}
{{entry.location}
{{entry.price}}
{{entry.contacts}
{{entry.visted}}
{%for entry.description.splitlines%}{{line}}
{%endfor%}
{%for entry.pros.splitlines%}{{line}}
{%endfor%}
{%for entry.cons.splitlines%}{{line}
{%endfor%}
删除
{%endfor%}
$(文档).ready(函数(){
$(“myTable td”)
.改变(功能){
控制台日志(“petar”);
var data=this.innerHTML;
console.log(“value=”+数据);
})
.change();
})) 使用Javascript的方法
或者方法
更改我(输入)!
改变我(模糊)代码>使用Javascript的方法
或者方法
更改我(输入)!
改变我(模糊)代码>此方式功能在按下每个字符/键盘时触发。我想实现的是键入一些文本,然后在输入所有文本后触发功能,例如,在鼠标上移动单元格(单元格失焦或什么的)是否签出?这就是我要找的东西。感谢您的帮助。此方式功能会在每个按下的字符/键盘上触发。我想实现的是键入一些文本,然后在输入所有文本后触发功能,例如,在鼠标上移动单元格(单元格失焦或什么的)是否签出?这就是我要找的东西。谢谢你的帮助。