The following code does not work on Safari mobile:
$("#button").click(function() {
$("fieldset").each(function() {
$(this).children(".input").detach().sort(function(a, b) {
return $(a).attr("data-sort") < $(b).attr("data-sort");
}).appendTo(this);
});
});
The html looks somewhat like this:
<fieldset>
<span class='input' data-sort='3'><input>.....</input></span>
<span class='input' data-sort='1'><input>.....</input></span>
<span class='input' data-sort='2'><input>.....</input></span>
</fieldset>
It works just fine on desktop. Any ideas of what's going on?
Fixed it. The callback function for .sort() was badly designed.
$("#button").click(function() {
$("fieldset").each(function() {
$(this).children(".input").detach().sort(function(a, b) {
var contentA =parseInt( $(a).attr('data-sort'));
var contentB =parseInt( $(b).attr('data-sort'));
return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
}).appendTo(this);
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.