问题
Hello I have created this list which changes the colour when you select an item using jQuery UI's selectable.
<ol id="selectable">
<li class="ui-widget-content" Name ='gender' value= 'male1'>Item 1</li>
<li class="ui-widget-content" Name ='gender' value= 'male2'>Item 2</li>
<li class="ui-widget-content" Name ='gender' value= 'male3'>Item 3</li>
<li class="ui-widget-content" Name ='gender' value= 'male4'>Item 4</li>
<li class="ui-widget-content" Name ='gender' value= 'male5'>Item 5</li>
<li class="ui-widget-content" Name ='gender' value= 'male6'>Item 6</li>
<li class="ui-widget-content" Name ='gender' value= 'male7'>Item 7</li>
</ol>
<Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button">
http://jsfiddle.net/szNh3/2/
Ho do I send/get the selected item in a php file?
回答1:
Slightly modified segment from the jQuery UI documentation
$(function() {
$( "#selectable" ).selectable({
stop: function() {
var result = $( "#select-result" ).empty();
$( ".ui-selected", this ).each(function() {
var index = $( "#selectable li" ).index( this );
// send an AJAX request to a PHP file
$.get('myphpfile.php', {
selectedIndex: index
}, function(data) {
// do stuff with the results from PHP
});
});
}
});
});
EDIT
To do this from your button
$(function() {
$( "#selectable" ).selectable();
$("submit[name=Submit1]").click(function() {
var index = $( "#selectable li" ).index( $("#selectable") );
$.get('myphpfile.php', {
selectedIndex: index
}, function(data) {
// do stuff with the results from PHP
});
});
});
来源:https://stackoverflow.com/questions/24618319/how-to-get-the-value-from-jquery-ui-selectable-in-php