0
我期待着擴展最近使用jquery編寫的腳本。jquery從兩個區域中刪除字符串部分
我有此以下代碼
<script type='text/javascript'>
added_departments = new Array();
$("#departments_submit").click(function(){
var depo = $("#depo_list").val();
if(jQuery.inArray(depo, added_departments) != -1)
{
return false;
}
else
{
added_departments.push(depo);
$("#depo_added_list").append("<li>" + depo + "<a href='#' title='"+ depo +"' class='remove_depo'> [X] </a></li>");
var current_value = $("#departments").val();
if(current_value)
{
$("#departments").val(current_value + "," + depo);
}
else
{
$("#departments").val(depo);
}
return false;
}
});
</script>
上述代碼發生在一個選擇下拉選擇向下框的信息,把它添加到一個div公開,並且還顯示成處理所述數據的隱藏的表單字段。
我試着創建一些東西,將扭轉這種效果,並從div和字段中刪除某些選擇。這是我的代碼
<script type='text/javascript'>
$(".remove_depo").click(function(){
var removing = $(this).title();
var current_val = $("#deparments").val();
if(current_val == removing) {
$("departments").replace(removing, "");
}
else {
$("departments").replace("," + removing, "");
}
});
</script>
它不會導致任何錯誤,但它也不會做任何事情嗎?所以我很困難。有任何想法嗎?
編輯:更新後的代碼
$(".remove_depo").click(function(){
var removing = $(this).attr('title');
var current_val = $("#deparments").val();
if(current_val == removing) {
$("#departments").replace(removing, "");
}
else {
$("#departments").replace("," + removing, "");
}
});
下面是HTML
<form method="post" action="javascript:void(0);">Select Departments To Be Added:
<div class="depo_adder">
<select id="depo_list"><option value="">--- INDIVIDUAL TAGS ---</option><option value="blah">blah</option></select>
<button id="departments_submit">Go!</button>
</div></form><form method="post" action="briefings/addbriefing.php">
<div class="form">
<strong>Departments: </strong>
<ul id="depo_added_list"><li>blah<a href="#" title="blah" class="remove_depo"> [X] </a></li></ul>
<input name="departments" id="departments" value="blah" type="hidden">
</div>
好的,我已經稍微改變了代碼...但是它仍然沒有按要求工作。 –