我一直在嘗試這個好一段時間,但我似乎無法添加更多選項到多選。我如何添加新的選項到JQuery UI多選
即使當我嘗試添加硬編碼信息時,它也不會被添加。 (Multiselect和JQuery的頭文件位於不同的文件中)。
您可以看到鏈接在這裏的行動: http://www.fakegaming.eu/GoT/index.php?act=selectteam&matchid=3
<?php
$matches = new Matches();
$user = new User();
$id = $_GET['matchid'];
$matchinfo = $matches->getmatch($id);
$matchplayers = $matches->getmatchplayers($id);
?>
<script type="text/javascript">
$(function(){
$.localise('ui-multiselect', {/*language: 'en',*/ path: 'script/locale/'});
$(".multiselect").multiselect();
$("#add").click(function() {
$('#players').multiselect('addOptions', 'Test=123');
alert("Handler for .click() called.");
});
});
</script>
Kies hier 10 spelers die mee doen aan de match.<br /> <br />
<form action='index.php?act=createteam' method='post'>
<select id="players" class="multiselect" multiple="multiple" name="players[]">
<?php
foreach($matchplayers as $matchplayer){
$userinfo = $user->getuserbyid($matchplayer['user_id']);
if($matchplayer['type'] == 0 OR $matchplayer['type'] == 2){
$name = $userinfo['EU_username'];
?>
<option value="<?= $name ?>"><?= $name ?></option>
<?php
}
}
?>
</select>
<input name='name' type='text' id='name' />
<input type='button' id="add" name="add" value="Toevoegen" />
<input name="submit" value="Maak team" type="submit" />
</form>
我可能只是做一些可怕的錯誤,但我只想好好多選一些名稱添加到它。
也許這不是問題,但是您是否嘗試過將'opt.text'和'opt.value' _before_添加到'players'中? – veeTrain