1

我有一个引导选择器。我有一个 timeRange 值的列表。

<select class="selectpicker">

<option data-icon="" value="00:00-23:59">All Day (12am-11:59pm)</option>
<option data-icon="fa fa-coffee" value="05:00-08:59">Morning (5am-8:59am)</option>
<option data-icon="fa fa-briefcase" value="09:00-16:59">Business Hours (9am-4:59pm</option>
<option data-icon="fa fa-moon-o" value="17:00-20:59">Evening (5pm-8:59pm)</option>
<option data-icon="fa fa-clock-o" value="00:00-11:59">AM Hours (12am-11:59am)</option><option data-icon="fa fa-clock-o" value="12:00-23:59">PM Hours (12pm-11:59pm)</option><option data-icon="fa fa-clock-o" value="00:00-05:59">12am-5:59am</option>
<option data-icon="fa fa-clock-o" value="06:00-11:59">6am-11:59am</option>
<option data-icon="fa fa-clock-o" value="12:00-17:59">12pm-5:59pm</option>
<option data-icon="fa fa-clock-o" value="18:00-23:59">6pm-11:59pm</option>

</select>

用例: 我想添加或删除其中一些并将生成的 JSON 发送到后端。

这是我尝试过的:

 http://jsfiddle.net/M69TH/18/

我有一个名为“删除”的按钮,如果我点击它,我想从选择器中删除一个 timeRanges 并将 JSON 重新发送到后端。

我怎样才能做到这一点?

4

1 回答 1

1

这将适用于从选择器中删除选定元素:

function modifications() {
  $('.selectpicker option:selected').remove();
  $('.selectpicker').selectpicker('refresh');
}

将 json 发送到后端:

function send() {
    var jsonData = {
         name: "value"; //change this according to your needs
    }

    $.ajax({
        url: 'backend url', //change this
        type: 'post',
        dataType: 'json',
        success: function (data) {
            // any msg you want to display on success
        },
        data: jsonData
    });
}
于 2016-08-25T19:43:12.337 回答