【发布时间】:2011-06-07 19:53:04
【问题描述】:
我的脚本有点问题。
目标:我有一个带有几个选项的select,如果您选择值为“4”的选项,则选择将删除,在这个地方我需要在跨度标签中插入 input[type=text] 和单词“remove” .现在,当您单击此跨度时,先前插入的输入和跨度将被删除,我需要在此放置先前删除的选择
我希望这是有道理的:-)
这里是我的 id=f9 表单中的 html 代码:
<label class="mandatory" for="ctrl_54">Title</label>
<select class="select mandatory" id="ctrl_54" name="title">
<option value="1">Books</option>
<option value="2">Movies</option>
<option value="3">Events</option>
<option value="4">other...</option>
</select>
还有我的 js:
function be_forms() {
var myselect = $('form#f9 select#ctrl_54');
if ($('form#f9').length) {
$('form#f9 select#ctrl_54').change(function() {
if ($(this).val() == 4) {
$('form#f9 select#ctrl_54').remove();
$('<input type="text" value="" class="text innyinput mandatory" id="ctrl_54" name="title" /><span class="remove">remove</span>').insertAfter('form#f9 label[for=ctrl_54]');
$("form#f9 span.remove").click(function(){
$('form#f9 input#ctrl_54').remove();
$('form#f9 span.remove').remove();
$(myselect).insertAfter('form#f9 label[for=ctrl_54]');
});
}
});
}
}
现在几乎一切正常。我的意思是当我选择值为 4 的选项时 - 选择是删除并出现输入和跨度。当我点击这个跨度时,我的选择再次出现,输入和跨度被删除。 但是现在,如果我在选择选项中再次选择值为 4 - 什么也不会发生。我想再做一次 - 删除选择,插入输入和跨度等等......
对不起,我的英语不是母语。
【问题讨论】: