jquery - Javascript - How do I call the object? -
As you can see I have created three objects, each has a different array. Whitesmate = {option: ["chicken", "turkey"]}, fish = Then, in HTML I have created a selection area with three similar options. Now, whenever the user selects the field, I want to be able to display the right array in my console. (For example, when red meat is selected, then the console "beef", "steak", "kangaroo" will be logged.) So the question is; How do I call an object? Firstly, you need to modify your object and put it into a single object. After that you can easily call the object and get its value. ["Chicken", "turkey"], fish: ["salmon", "white", "meat", "meat", " Tuna "]}; $ ('Choose [name = meat-type]'). Change (function () {console.log (meatObj [this.value]);}); for the above code
& lt; Choose name = "meat-type" & gt; & Lt; Option value = "redmeat" & gt; Red flesh & lt; / Options & gt; & Lt; Option value = "whitet" & gt; White meat & lt; / Options & gt; & Lt; Option value = "fish" & gt; Fish & lt; / Options & gt; & Lt; / Select & gt;
$ ('select [name = meat - type] ') .change (function () {var e = $ ("select [name = meat-type] option: selected") Val (); function updatefield (e) {console.log (e); / / This works, easy .f = e.options; // But it does not work, returns the undefined console.log (f);}; updatefield (e);});
Comments
Post a Comment