我有以下代码完美的作品,但我需要一个onblur语句,如果用户点击离开下拉,因此把它回到它的原始状态 - 但试图实现这一点和不知道从哪里开始。如何onblur退出功能
下面的代码:
<script>
$(document).ready(function(){
var choices = "<select class='choices'>"
+"<option value='Choice 1'>Choice 1</option>"
+"<option value='Choice 2'>Choice 2</option>"
+"<option value='Choice 3'>Choice 3</option>"
+"<option value='Choice 4'>Choice 4</option>"
+"</select>";
$(".update").click(function() {
var $this = $(this),
currentChoice;
// don't continue if there's already a select in this cell
if ($this.find("select").length != 0)
return;
currentChoice = $this.html();
var $choices = $(choices);
$this.empty().append($choices);
$choices.val(currentChoice);
});
$(document).on("change", ".choices", function() {
var $this = $(this);
$this.parent().html($this.val());
return false;
});
});
</script>
<table id="list">
<tr>
<td>Film Name 1</td>
<td class="update">Choice 1</td>
</tr>
<tr>
<td>File Name 2</td>
<td class="update">Choice 3</td>
</tr>
<!-- etc -->
</table>
而且,我可以再使用onchange="this.form.submit();"
提交变更到我的MySQL数据库?
非常感谢这一点,那么最后一个难题是用户点击,这会关闭事件,这很好,如果用户点击选择2,它会关闭事件选择1?基本上这意味着每次只能打开一个选择框 - 我想这会使其结束 – 2012-01-04 10:56:53
@Darren - 当然,请参阅我的编辑。 – 2012-01-04 12:03:27