jquery - JqueryUI Spinner issue -
hi having problems inserting spinner jquery ui. below code, can me, grateful. cant appear makes work disappear :s
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> //this creates spinner each of weighting boxes user have easier way of selecting desired values $(function() { var spinner = $( "x" ).spinner({ min:0}); var spinner = $( "y" ).spinner({ min:0}); var spinner = $( "z" ).spinner({ min:0}); }); $(document).ready(function() { var x ='x'; var y = 'y'; var z = 'z'; // user variables declared $('<tr><td>'+x+'</td>' + '<td><input id="'+x+'" class="textbox" type="text" id = "x" value="1" />'+ // text boxes each variable created '</td></tr>').appendto('#menu'); $('<tr><td>'+y+'</td>'+ '<td><input id="'+y+'" class="textbox" type="text" id = "y" value="1" />'+ '</td></tr>').appendto('#menu'); $('<tr><td>'+z+'</td>'+ '<td><input id="'+z+'" class="textbox" type="text" id = "z" value="1" />'+ '</td></tr>').appendto('#menu');
there many errors post comment here (be aware don't know whole code/html markup looks errors aren't real errors perhaps)
first of there no jquery ui script tag in code. guess case code example , not whole code. if not:
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> in $(function() { }); creates spinner each weighting box. declare , overwrite 1 variable ( var spinner) 3 times. not necesarry use variables it. anyway:
$(document).ready(function() { var spinnerone = $( "#x" ).spinner({ min:0}); var spinnertwo = $( "#y" ).spinner({ min:0}); var spinnerthree = $( "#z" ).spinner({ min:0}); //alternative without using variables: $('#x').spinner({ min: 0 }); }); i changed selectors e.g. $( "z" ) $( "#z" ) because want init spinners on <inputs>s specified id.
$('#element') selector element id "element" (usually one)
$('.element'). selector elements class "element" (if more 1 class exists selected)
this in css select class of elements dot . , id hash #
because named id topic. of input fields have two ids id unique identifier. (perhaps there in sample code show tried)
you need correct them this
<input class="textbox" type="text" id="x" value="1" /> in fact there's no need connecting + because try append html (except '<tr><td>'+x+'</td>')
it's redundant write spinners in seperate function. $(function () { });and $(document).ready(function () { });are same purpose. see stackoverflow thread more information. can't work initialize spinners before creating elements spinners should created. i'm not sure why create elements in $(document).ready() because in html template.
i'd recommend create jsfiddle. provides more accurate view of problem have resp. current progress is. helpful describe problem , doesn't work in context.
here working example of markup in modified way. please sure know do.
Comments
Post a Comment